Reputation: 27816
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?
Upvotes: 72
Views: 38952
Reputation: 7072
If you just the test case list, but you don't want to the XML result, not checking the setups and teardowns, you can use pytest --co -q
.
That way you just have the list of testcases like:
tests/test_file.py::test_mytc1
tests/test_file.py::test_mytc2
tests/test_file_2.py::test_yourtc1
tests/test_file_2.py::test_yourtc2
Upvotes: 0
Reputation: 101
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 test_file.py>
# <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/test_file.py
# SETUP [...]
# tests/test_file.py::test__my_awesome_code_does_the_awesome_thing (fixtures used: [...])
# TEARDOWN [...]
Upvotes: 10
Reputation: 69755
You should use the flag --collect-only
. If you are using pytest
5.3.0 or newer use --co
.
pytest --co
pytest --collect-only
You can use this flag among other flags, so in your case pytest --co -k PATTERN
.
Upvotes: 23
Reputation: 6357
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.
Upvotes: 91
Reputation: 1399
-v verbose tells you which test cases are run, i.e. which did match your PATTERN.
Upvotes: 3