Run just a group of tests

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: (

  2. class MyTests(mocker.MockerTestCase):
  3. def test_method1():
  4. pass
  5. def test_method2():
  6. pass
  7. def test_method3():
  8. pass
  10. if __name__ == "__main__":
  11. if len(sys.argv) < 2:
  12. unittest.main(argv = unittest.sys.argv + ['--verbose'])
  13. else:
  14. suite = unittest.TestSuite()
  15. for i in range(1, len(sys.argv)):
  16. suite.addTest(MyTests(sys.argv[i]))
  17. runner = unittest.TextTestRunner()

Invocation samples:

  2. python # all the tests in the TestCase
  3. python 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.

  • Cristobal Yerger

    I have been exploring for a little bit for any high quality articles or blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this web site. Reading this info So i am happy to convey that I have a very good uncanny feeling I discovered exactly what I needed. I most certainly will make sure to do not forget this website and give it a look regularly.