-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest --collect-only --quiet
output is not "machine readable"
#9704
Comments
I have a similar problem: I would expect that providing Inspecting the code I noticed that decreasing the verbosity might help: pytest/src/_pytest/terminal.py Lines 1036 to 1038 in 00ad12b
So, I tried doing that and for the following sample repo: #!/bin/bash
mkdir tests
echo -e "def test_very_important():
assert 1+1 == 2
" > tests/test_something.py I tried running with $ pytest --collect-only -q
tests/test_something.py::test_very_important
1 test collected in 0.00s $ pytest --collect-only -qq
tests/test_something.py: 1
My question is: is this behavior expected? Is there a way to get just tests/test_something.py::test_very_important ? If it would be expected to display only the list of tests in one of the cases, I am willing to prepare a fix. I would appreciate some context thought, because I am not sure in which case should it be. |
I believe there are many ways to do this E.g. Shell approach: pytest --collect-only -q tests/test_hello.py | head -n -2 | python -c 'import sys; tests=[i.strip() for i in sys.stdin.readlines()]; print(tests)' Python approach: import pytest
class MyCollectionPlugin:
def __init__(self):
self.tests = []
def pytest_report_collectionfinish(self, items):
self.tests = [item.nodeid for item in items]
if __name__ == "__main__":
p = MyCollectionPlugin()
pytest.main(["--collect-only"], plugins=[p])
print(p.tests)
# generate_json_from_items_nodeid_list(p.tests) |
@asottile i tihnk this may be a nice chance to introduce some type of jsonlines based output for pytest that is similar to report log, but adds extras that other ux tools might be able to use |
@elbehery95 adding a plugin of course makes this possible but the ask is for pytest to do this itself |
The idea of |
I'm all for extending |
Should we create the issue in |
Hi, What's the status on this? A |
Yep, this already works fine with pytest-reportlog and |
What'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.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: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
The text was updated successfully, but these errors were encountered: