Show Menu

Pytest is one of the best tools used to boost software testing productivity.


pytest test_m­
Run tests in a module.
pytest testing/
Run tests in a directory.
pytest test_m­od.p­y:­:te­st_func
Run a specific test within a module.
pytest test_m­od.p­y:­:Te­stC­las­s::­tes­t_m­ethod
Run a specific method of a class.


-k "­exp­res­sio­n"
Run tests by keyword expres­sion.
-m "­exp­res­sio­n"
Run tests by marker expres­sion.
Shows builtin and custom fixtures.
Shows builtin and custom markers.
--lf, --last­-failed
Run only the failed tests from the previous run.
--ff, --fail­ed-­first
Rerun the failures first and then successful tests.
-x, --exit­first
Exit immedi­ately on first error or failed test.


-v, --verbose
More verbosity.
-q, --quiet
Less verbosity.
Disable the display of warnings summary.
Generate the HTML report at given path [pytes­t-h­tml].
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)se­lection of groups:
a - all except pP
A - all
N - none, this can be used to display nothing (since fE is the default)


Show local variable in traceback.
Show complete traceb­acks. Default is to cut.
Pytest places a debugger breakpoint whenever an error occurs in tests.
Collect tests, don't execute them.
Lists all the Pytest and dependent packages command line options.

Parall­eli­zation [pytes­t-x­dist]

-n numpro­cesses
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 distri­bution algorithm with the --dist option.
Distri­buting algorithm values are
no: --nump­roc­esses 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 [pytes­t-t­est­rail]

Create and update testruns.
Defaults to testra­il.cfg .
Name given to Testrun.
pytest --testrail --tr-c­onfig= testra­il.cfg
Testrail config file template:
url = https:­//y­our­url.te­str­
email = user@e­mai­
password = <ap­i_k­ey>

assign­edto_id = <us­er-­id>
project_id = <pr­oje­ct-­id>
suite_id = <te­st-­sui­te-­id>
name = <te­st-­run­-na­me>


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet