Sometimes we (my team in our current project) have a single TestCase (class) holding tests for several SUTs (classes). That is not right as every class should have its own TestCase (It has to do with the fact that instantiating the tests to run them is a pain with unitttest), however it is our actual situation.
In order to run just the tests belonging to the current SUT, just pass them in as parameters: (tests.py)
class MyTests(mocker.MockerTestCase): def test_method1(): pass def test_method2(): pass def test_method3(): pass if __name__ == "__main__": if len(sys.argv) < 2: unittest.main(argv = unittest.sys.argv + ['--verbose']) else: suite = unittest.TestSuite() for i in range(1, len(sys.argv)): suite.addTest(MyTests(sys.argv[i])) runner = unittest.TextTestRunner() runner.run(suite)
python tests.py # all the tests in the TestCase python tests.py test_method1 test_method2 # only these two
This way we run all the tests all the time, instead of just running the test we've done writing.