terminal: add --name-only option to show only names of failed tests
What's the problem this feature will solve?
When running large test suites, failed tests often produce a significant amount of output including tracebacks, captured logs, and stdout/stderr. If many tests fail simultaneously, identifying the specific tests that failed becomes difficult as the names are buried under pages of detailed error information. While options like -q or --tb=no exist, they often hide too much information or don't provide the structured "FAILURES" and "ERRORS" sections that help in quickly scanning results.
Describe the solution you'd like
A new command-line option --name-only that modifies the terminal output to only show the names of failed or erring tests.
When enabled:
- The FAILURES section lists only the test names (e.g., test_fail1).
- The ERRORS section lists the error headlines (e.g., ERROR at setup of test_error or ERROR collecting
test_file.py). - All detailed tracebacks and captured output sections are suppressed for these failures.
Example output:
1 ============================= FAILURES =============================
2 test_fail1
3 test_fail2
4 ====================== short test summary info ======================
5 FAILED test_file.py::test_fail1 - assert False
6 FAILED test_file.py::test_fail2 - assert False
7 ========================= 2 failed in 0.05s =========================
Alternative Solutions
- Using
--tb=noor--tb=line: These reduce output but either remove the summary headers entirely or still include error messages that can be quite verbose. - Piping to grep: Users often pipe pytest output to grep to extract failure names, but this is fragile and loses pytest's color formatting and structural grouping.
PR
I’d like to implement this. I can add a --name-only option for failed tests, cover it in terminal reporter tests, and make sure it composes cleanly with existing verbosity and failure output options. Please assign this to me.
I’d like to implement this. I can add a --name-only option for failed tests, cover it in terminal reporter tests, and make sure it composes cleanly with existing verbosity and failure output options. Please assign this to me.
I think it has been handled on the PR of the same number
the functionality as proposed is porblematic without more context as hiding the tracebacks/errrors removes direct reading/debugging
the common solution in ci/cd is for people to have something like a junitxml report and a test result overview
having a better ux for subpar CI/CD systems that lack result ingestion/presentation ux is something that only partially touches the ux surface of pytest and needs a more nuanced discussion
The main idea, was that into the pre-commits you may like to launch test but it is not the proper place to see the traceback of the errors. During pre-commits you only need the name of the tests that does not work then debug if needed.
In addition, for me, adding junitxml is big dependencies just to say that there is an error. In fact, you often need to know that you have an error and you'll debug it locally or on a specific object (docker etc)