Run tests only if Python2 is used, print warning otherwise.
-
mentioned in merge request nexedi/slapos.buildout!19 (closed)
-
[ continuing nexedi/slapos.buildout!19 (comment 96171) ]
I think your idea to "disable" test directly in the python code and not in buildout makes sense. I feel we can use unittest "skip" here, it's also supported in our test integration. I see we can use a
skipIf
decorator on the class, so maybe we can put it on theCaucaseTest
class, for example:import unittest import sys @unittest.skipIf(sys.version_info >= (3, ), 'Caucase currently supports python 2 only') class Test(unittest.TestCase): def test_a(self): self.assertEqual('a', 'A') def test_b(self): self.assertEqual('b', 'B')
$ python2 -m unittest test FF ====================================================================== FAIL: test_a (test.Test) ---------------------------------------------------------------------- Traceback (most recent call last): File "test.py", line 7, in test_a self.assertEqual('a', 'A') AssertionError: 'a' != 'A' ====================================================================== FAIL: test_b (test.Test) ---------------------------------------------------------------------- Traceback (most recent call last): File "test.py", line 9, in test_b self.assertEqual('b', 'B') AssertionError: 'b' != 'B' ---------------------------------------------------------------------- Ran 2 tests in 0.000s FAILED (failures=2) $ python3 -m unittest test ss ---------------------------------------------------------------------- Ran 2 tests in 0.000s OK (skipped=2)
/cc @vpelletier @luke
PS: To apply the same on kedifa it's a bit more complex because caucase uses some python2 only syntax, but it's maybe only with
print
. When usingfrom __future__ import print_function
then python2's print behaves same as python3's one so that could be a way. It was done in jerome/kedifa@0ffdfacf , with lots of other "not ready" changes .