List available tests with py.test


I can’t find a way to list the tests which I can call with py.test -k PATTERN

How can I see the list of the available tests?

Asked By: guettli



-v verbose tells you which test cases are run, i.e. which did match your PATTERN.

Answered By: Zdenek Maxa

You can also use --collect-only, this will show a tree-like structure of the collected nodes. Usually one can simply -k on the names of the Function nodes.

Answered By: flub

You should use the flag --collect-only. If you are using pytest 5.3.0 or newer use --co.

pytest 5.3.0+

pytest --co

previous versions

pytest --collect-only

You can use this flag among other flags, so in your case pytest --co -k PATTERN.

Answered By: lmiguelvargasf

Both –collect-only and –setup-plan will print out your test files and individual tests.

--collect-only (or --co) prints in a <[type] [name]> format

pytest --collect-only
# or
pytest --co

# <Module>
#   <Function test__my_awesome_code_does_the_awesome_thing>

--setup-plan is more verbose and prints the entire test-run plan (including any setup, teardown, and fixtures used for each test). It also prints the entire path for each test.

pytest --setup-plan

# tests/
#     SETUP    [...]
#     tests/ (fixtures used: [...])
#     TEARDOWN [...]
Answered By: Mandi.Alexander
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.