Pytest
Contents
Pytest#
Pytest is a tool for writing and running tests.
See also
Install#
poetry add --dev pytest
Version 1.2.1
and newer use:
poetry add --group dev pytest
python -m pip install pytest
Usage#
Getting Help#
Running Tests#
Verbose Mode#
[ ] invocation (run)
[ ] help
[ ] running a single test (
-k
or test_name.py::test_name)[ ] verbose mode
[ ]
-v
: verbose[ ]
-x
: fail on first tests[ ]
-k
: expression[ ]
-tb=short
: shorter tracebacks[ ]
--pdb
: start debugger on failures[ ]
--trace
: start debugger with breakpoint at the beginning of each test[ ]
--pdbcls=IPython.terminal.debugger:TerminalPdb
: use the ipython debugger[ ] running single test, filtering to matching names
Quickref#
Flag |
Description |
---|---|
|
Help |
|
Exit on first error |
|
start debugger on error |
|
add breakpoint to beginning of each test |
|
don’t capture stdout and stderr |
|
show local variable and their values |
|
print shorter tracebacks |
See also#
See also
TODO#
[x] install
[ ] setup
[ ] pyproject.html: testpaths, addopts
[ ] conftest.py
[ ] plugins
[ ] pytest-only (add only marker)
[ ] pytest-parametrization
[ ] pytest-clarity (prettier assert diffs)
[ ] adding to
pyproject.toml
[tool.pytest.ini_options] testpaths = ["tests"] addopts = "-vx"