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:
- Classes that start with Test, in a file that starts with test
- Functions that start with test, in a file that starts with test
The following are the advantages of py.test over other frameworks:
- The ability to easily disable selected test classes
- A flexible and original mechanism for dealing with fixtures
- The built-in ability to distribute tests among several computers
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.