Note
If you don’t find an answer here, checkout the Contact channels to get help.
Some of the reasons are historic, others are practical. py.test used to be part of the py package which provided several developer utilities, all starting with py.<TAB>, thus providing nice TAB-completion. If you install pip install pycmd you get these tools from a separate package. These days the command line tool could be called pytest since many people have gotten used to the old name and there is another tool named “pytest” we just decided to stick with py.test.
py.test and nose share basic philosophy when it comes to running and writing Python tests. In fact, you can run many tests written for nose with py.test. nose was originally created as a clone of py.test when py.test was in the 0.8 release cycle. Note that starting with pytest-2.0 support for running unittest test suites is majorly improved and you should be able to run many Django and Twisted test suites without modification.
Around 2007 (version 0.8) some people claimed that py.test was using too much “magic”. Partly this has been fixed by removing unused, deprecated or complicated code. It is today probably one of the smallest, most universally runnable and most customizable testing frameworks for Python. However, py.test still uses many metaprogramming techniques and reading its source is thus likely not something for Python beginners.
A second “magic” issue arguably the assert statement debugging feature. When loading test modules py.test rewrites the source code of assert statements. When a rewritten assert statement fails, its error message has more information than the original. py.test also has a second assert debugging technique. When an assert statement that was missed by the rewriter fails, py.test re-interprets the expression to show intermediate values if a test fails. This second technique suffers from caveat that the rewriting does not: If your expression has side effects (better to avoid them anyway!) the intermediate values may not be the same, confusing the reinterpreter and obfuscating the initial error (this is also explained at the command line if it happens). You can turn off all assertion debugging with py.test --assertmode=off.
For simple applications and for people experienced with nose or unittest-style test setup using xUnit style setup probably feels natural. For larger test suites, parametrized testing or setup of complex test resources using funcargs may feel more natural. Moreover, funcargs are ideal for writing advanced test support code (like e.g. the monkeypatch, the tmpdir or capture funcargs) because the support code can register setup/teardown functions in a managed class/module/function scope.
We like Convention over Configuration and didn’t see much point in allowing a more flexible or abstract mechanism. Moreover, is is nice to be able to search for pytest_funcarg__MYARG in a source code and safely find all factory functions for the MYARG function argument.
There are two conceptual reasons why yielding from a factory function is not possible:
Use the pytest_generate_tests hook to solve both issues and implement the parametrization scheme of your choice.
On windows the multiprocess package will instantiate sub processes by pickling and thus implicitly re-import a lot of local modules. Unfortunately, setuptools-0.6.11 does not if __name__=='__main__' protect its generated command line script. This leads to infinite recursion when running a test that instantiates Processes.
A good solution is to install Distribute as a drop-in replacement for setuptools and then re-install pytest. Otherwise you could fix the script that is created by setuptools by inserting an if __name__ == '__main__'. Or you can create a “pytest.py” script with this content and invoke that with the python version:
import pytest
if __name__ == '__main__':
pytest.main()