Commit 6e2b256f authored by Ivan Tyagov's avatar Ivan Tyagov

Run tests only if Python2 is used, print warning otherwise.

parent be9ef7a2
......@@ -2882,4 +2882,8 @@ if getattr(CaucaseTest, 'assertItemsEqual', None) is None: # pragma: no cover
# pylint: enable=no-member
if __name__ == '__main__': # pragma: no cover
unittest.main()
if sys.version_info.major == 2:
# currently we support only Python2
unittest.main()
else:
print "caucase supports only Python2."
  • mentioned in merge request nexedi/slapos.buildout!19 (closed)

    Toggle commit list
  • [ 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 the CaucaseTest 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 using from __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 .

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment