Cheatography
https://cheatography.com
Pytest is one of the best tools used to boost software testing productivity.
Basicpytest test_mod.py | Run tests in a module. | pytest testing/ | Run tests in a directory. | pytest test_mod.py::test_func | Run a specific test within a module. | pytest test_mod.py::TestClass::test_method | Run a specific method of a class. |
General-k "expression" | Run tests by keyword expression. | -m "expression" | Run tests by marker expression. | --fixtures | Shows builtin and custom fixtures. | --markers | Shows builtin and custom markers. | --lf, --last-failed | Run only the failed tests from the previous run. | --ff, --failed-first | Rerun the failures first and then successful tests. | -x, --exitfirst | Exit immediately on first error or failed test. |
Reporting-v, --verbose | More verbosity. | -q, --quiet | Less verbosity. | --disable-warnings, --disable-pytest-warnings | Disable the display of warnings summary. | --html=path | Generate the HTML report at given path [pytest-html]. | -r | Display a short test summary info. |
The -r option accepts a number of characters after it. Default is fE to list failures and errors.
f - failed
E - error
s - skipped
x - xfailed
X - xpassed
p - passed
P - passed with output
Special characters for (de)selection of groups:
a - all except pP
A - all
N - none, this can be used to display nothing (since fE is the default)
| | Debugging-l, --showlocals | Show local variable in traceback. | --full-trace | Show complete tracebacks. Default is to cut. | --pdb | Pytest places a debugger breakpoint whenever an error occurs in tests. | --co, --collect-only | Collect tests, don't execute them. | --help | Lists all the Pytest and dependent packages command line options. |
Parallelization [pytest-xdist]-n numprocesses | Number of processes to start. Can be a positive integer or Use 'auto' for auto detection CPUs number. | --dist no/ loadscope/ loadfile | Select the test distribution algorithm with the --dist option. |
Distributing algorithm values are
no: --numprocesses will send pending tests to any worker that is available, without any guaranteed order.
loadscope: Tests are grouped by the module for test functions and by class for test methods.
loadfile: Tests are grouped by their containing file.
Testrail [pytest-testrail]--testrail | Create and update testruns. | --tr-config=path | Defaults to testrail.cfg . | --testrail-run-name | Name given to Testrun. |
pytest --testrail --tr-config= testrail.cfg
Testrail config file template:
[API]
url = https://yoururl.testrail.net/
email = user@email.com
password = <api_key>
[TESTRUN]
assignedto_id = <user-id>
project_id = <project-id>
suite_id = <test-suite-id>
name = <test-run-name>
|
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets