python - Does setUp method from unittest.TestCase know the current test case? -
does setup method unittest.testcase knows next test case executed? example:
import unittest class tests(unittest.testcase): def setup(self): print "the next test be: " + self.next_test_name() def test_01(self): pass def test_02(self): pass if __name__ == '__main__': unittest.main()
such code should produce upon execution:
the next test be: test_01 next test be: test_02
no, unittest
makes no guarantee order of test execution.
moreover, should structure unit tests not rely on particular order. if require state setup test method no longer have, definition, unit test.
the current test method name executed lives in self._testmethodname
, use @ own risk (accessing _private
attributes subject breakage without warning). not use customise setup
based on particular test method, prefer split tests requiring different setup off separate test classes.
Comments
Post a Comment