With the unittest
module, I like the feature to skip tests, but it is only available in Python 2.7+.
For example, consider test.py
:
import unittest
try:
import proprietary_module
except ImportError:
proprietary_module = None
class TestProprietary(unittest.TestCase):
@unittest.skipIf(proprietary_module is None, "requries proprietary module")
def test_something_proprietary(self):
self.assertTrue(proprietary_module is not None)
if __name__ == '__main__':
unittest.main()
If I try to run a test with an earlier version of Python, I get an error:
Traceback (most recent call last):
File "test.py", line 7, in <module>
class TestProprietary(unittest.TestCase):
File "test.py", line 8, in TestProprietary
@unittest.skipIf(proprietary_module is None, "requries proprietary module")
AttributeError: 'module' object has no attribute 'skipIf'
Is there a way to "trick" older versions of Python to ignore the unittest decorator, and to skip the test?
DeprecationWarning: Use of a TestResult without an addSkip method is deprecated self._addSkip(result, skip_why)
I was unable to get it to disappear quickly. – Findley