Using pytest and Tox
So far, all the tests we have written used ;unittest.TestCase
classes and unittest.main()
to run them. As your project grows, you will have more and more tests modules around.
To automatically discover and run all the tests in a project, the unittest
package has introduced a Test Discovery feature in Python 3.2, which finds and runs tests given a few options. This feature has been around for a while in projects like Nose (https://nose.readthedocs.io) and pytest, and that's what inspired the unittest
package in the standard library.
Which runner to use is a matter of taste, and as long as you stick to writing your tests in TestCase
classes, your tests will be compatible with all of them.
That said, the pytest project is very popular in the Python community, and since it offers extensions, people have started to write useful tools around it. Its runner is also quite efficient, as it starts to run the tests while they are still discovered in the background, making it a little...