1

I have a unittest test case in my app which needs to be py2 and py3 compatible.

class MyTest(TestCase):
   def test_pep3102(self):
      def fn(a, b, *, d):
         pass
      
      # do something
      # assert

This test case works fine with py3 since py3 supports the signature of fn however fails as expected in py2 due to syntax error during module loading

What's the recommended way to deal with this?

I'm thinking of moving it out to a different file and loading it if py > 3 but wanted to know if there's a cleaner solution

Krimson
  • 7,386
  • 11
  • 60
  • 97
  • I would probably move it out (also expecting that the Py2 test will go away at some time). If you don't want this, you could use `def fn(*args, **kwargs)` and manually check for the arguments (and raise if there are more than 2 args in Python 3), though that is a bit awkward IMO. – MrBean Bremen Jun 21 '20 at 19:43

0 Answers0