`pytest --collect-only --quiet` output is not "machine readable"
See original GitHub issueWhat’s the problem this feature will solve?
I would like to programmatically collect the list of test ids from pytest.
current pytest --collect-only --quiet gets close, but has some non-machine-readable output at the end which is not desirable.
$ pytest --collect-only --quiet tests | tail -5
tests/astpretty_test.py::test_typedast_support_cmdline_27
tests/astpretty_test.py::test_typedast_support_cmdline_3
tests/astpretty_test.py::test_pformat_py38_type_comments
28 tests collected in 0.02s
Describe the solution you’d like
I would like to add either a --json output to this so it can be machine-parsed. perhaps a structure like:
$ pytest --collect-only --json
{
"testids": [
"...",
"...",
"..."
]
}
Alternative Solutions
I could write a plugin, but…
Additional context
I’m writing a tool to detect test pollution automatically. also I suspect this would be useful for those attempting to distribute tests by id across runners – for instance pytest-select
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Managing pytest's output — pytest documentation
By default no output will be shown (because KeyboardInterrupt is caught by pytest). ... To create plain-text machine-readable result files you can issue:....
Read more >using pytest --collect-only to only return individual test names
Why should I supply --quiet to be able to list the full name of my tests - it makes no sense. I believe...
Read more >Improving pytest's --collect-only Output | Hugo Martins
I have made a few changes in the way pytest processes the results of test ... pytest --collect-only ==== no tests ran in...
Read more >pytest Documentation - Read the Docs
Execute the test function with “quiet” reporting mode: ... By default, pytest will not show test durations that are too small (<0.005s) ...
Read more >Testing — transformers 3.4.0 documentation - Hugging Face
pytest -k "ada and not adam" tests/test_optimization.py. Copy to clipboard ... To have no color (e.g., yellow on white background is not readable):....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@elbehery95
head -2andstripare both hacks indicating that there is not structured output which is entirely what this issue is asking for – you’ll note that the original issue shows exactly the command you’re using and doesn’t helpadding a plugin of course makes this possible but the ask is for pytest to do this itself
I believe there are many ways to do this E.g.
Shell approach:
Python approach: