Python unittest does not run tests

There are three gotcha's that I know of:

  1. Your tests in your TestCases need to be named test_*
  2. Your test files need to be named: test*.py (by default, you can change it with the -p flag when running the tests). e.g.
  3. Your tests folder needs to have an file in it, or else it won't be considered a valid location to import from.

So, for #1, you need to rename the test to test_name_1. And for #2, there's two options:

A - Restructure your files like this:


Then run python -m unittest and it should find the test cases.

B - Just run it like: python -m unittest discover -p *

I fought with the same exact problem a while ago and I solved it by using test discovery command.

python -m unittest discover -s .

You can pass in your test file pattern as well and a whole other options