py.test

py.test is very similar to nose. In fact, the latter was inspired by py.test, so we will focus mainly on details that make these tools different from each other. The tool was born as part of a larger package called py, but now these are developed separately.

Like every third-party package mentioned in this book, py.test is available on PyPI and can be installed with pip as pytest, as follows:

$ pip install pytest

From there, a new py.test command is available in your shell that can be used exactly like nosetests. The tool uses similar pattern matching and test discovery algorithms to find tests in your project. The pattern is slightly stricter and will only match the following:

Be careful to use the right character case. If a function starts with a capital T, it will be taken as a class, and thus ignored. And if a class starts with a lowercase t, py.test will break because it will try to deal with it like a function.

The following are the advantages of py.test over other frameworks:

In the following sections, we will take a look at writing test fixtures, disabling test functions and classes, and automated distributed tests in py.test.