pytest module
Date: January 16th 2016
Last updated: January 16th 2016
pytest can run tests suites from unittest doctest and nose modules. For documentation see their webpage and pytest.pdf. Installation and setup is similar to nose.
# install latest pytest
pip install -U pytest
# print version of pytest
py.test --version
# Output:
#This is pytest version 2.8.5, imported from ...snipped...
#anaconda2/lib/python2.7/site-packages/pytest.pyc
# get help
py.test --help
Assuming the existing file structure from testing with nose:
Project
├── test
│ ├── __init__.py
│ ├── test_vowels_nose.py # nose test script
│ └── test_vowels.py # unittest test script
└── vowels
├── __init__.py
├── vowelsclass.py # new vowels script
└── vowels.py
Run existing test functions:
# run at Project directory with auto-discovery
py.test
# specify one file
py.test test/test_vowels.py
# stop after first failure
py.test -x
# stop after N=4 failures
py.test --maxfail=4
# verbosity
py.test -v
# quiet
py.test -q
Debuggers:
# doctests
py.test --doctest-modules
# pdb
py.test -x --pdb # on first failure
py.test --maxfail=2 # go tp pdb for the first two failures
Output from a failed test (modified test_vowels.py to fail):
Output of a failed doctest: