other

[pytest] Running pytests with options

Example:
$ ​​pytest​​ ​​--tb=short​​ tests

--tb=style
short prints just the assert line and the E evaluated line with no context; 
line keeps the failure to one line; 
no removes the traceback entirely.

$ ​​pytest​​ –collect-only tests
shows which tests will be run with the given options and configuration

$ ​​pytest​​ -v ​​-k​​ ​​"dashboard"​​ ​​--collect-only​
lists the test_dashboard() tests only

​import​ pytest ...
@pytest.mark.run_these_please ​def​ test_member_access():
...

$ ​​pytest​​ ​​-v​​ ​​-m​​ ​​run_these_please​
mark and run a subset of test functions

​$ ​​pytest​​ ​​-x​
​$ ​​pytest​​ ​​-exitfirst
stopping the entire test session immediately when a test fails

-k EXPRESSION only run tests/classes which match the given substring expression.
Example: -k 'test_method or test_other' matches
all test functions and classes whose name
contains 'test_method' or 'test_other'.
-m MARKEXPR only run tests matching given mark expression. example: -m 'mark1 and not mark2'.
-x, --exitfirst exit instantly on first error or failed test. 
--maxfail=num exit after first num failures or errors. 
--capture=method per-test capturing method: one of fd|sys|no.
-s shortcut for --capture=no.
--lf, --last-failed rerun only the tests that failed last time
(or all if none failed)
--ff, --failed-first run all tests but run the last failures first.
-v, --verbose increase verbosity.
-q, --quiet decrease verbosity.
-l, --showlocals show locals in tracebacks (disabled by default). 
--tb=style traceback print mode (auto/long/short/line/native/no). 
--durations=N show N slowest setup/test durations (N=0 for all). 
--collect-only only collect tests, don't execute them.
--version display pytest lib version and import information.
-h, --help show help message and configuration info
Was this helpful?