Running a single test from unittest.TestCase via the command line Running a single test from unittest.TestCase via the command line python python

Running a single test from unittest.TestCase via the command line


This works as you suggest - you just have to specify the class name as well:

python testMyCase.py MyCase.testItIsHot


If you organize your test cases, that is, follow the same organization like the actual code and also use relative imports for modules in the same package, you can also use the following command format:

python -m unittest mypkg.tests.test_module.TestClass.test_method# In your case, this would be:python -m unittest testMyCase.MyCase.testItIsHot

Python 3 documentation for this: Command-Line Interface


It can work well as you guess

python testMyCase.py MyCase.testItIsHot

And there is another way to just test testItIsHot:

    suite = unittest.TestSuite()    suite.addTest(MyCase("testItIsHot"))    runner = unittest.TextTestRunner()    runner.run(suite)