-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
terminal: add --name-only option to show only names of failed tests #14451
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
base: main
Are you sure you want to change the base?
Changes from all commits
f717d96
98c06dc
b15932f
8d06b7e
5bb60f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -504,6 +504,7 @@ Warren Markham | |
| Wei Lin | ||
| Wil Cooley | ||
| Will Riley | ||
| Willem Adnet | ||
| William Lee | ||
| Wim Glenn | ||
| Wouter van Ackooy | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added new CLI argument ``--name-only`` to only display the name of the test when it fails, suppressing tracebacks and other detailed information. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| from __future__ import annotations | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR tests --name-only with --tb=line, but what about other combinations like --name-only with --show-capture=no or with verbose flags? Consider adding a test that ensures these play nicely together => Add tests for combinations like --name-only -v and document expected behavior |
||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| class TestNameOnly: | ||
| def test_name_only_failures(self, pytester: pytest.Pytester) -> None: | ||
| pytester.makepyfile( | ||
| """ | ||
| def test_fail1(): | ||
| assert False | ||
| def test_fail2(): | ||
| assert False | ||
| def test_pass(): | ||
| assert True | ||
| """ | ||
| ) | ||
| result = pytester.runpytest("--name-only") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "=* FAILURES *=", | ||
| "test_fail1", | ||
| "test_fail2", | ||
| "=* short test summary info *=", | ||
| ] | ||
| ) | ||
|
|
||
| output = result.stdout.str() | ||
| failures_part = output.split("FAILURES")[1].split("short test summary info")[0] | ||
| assert "test_fail1" in failures_part | ||
| assert "test_fail2" in failures_part | ||
| assert "assert False" not in failures_part | ||
| assert "E assert False" not in failures_part | ||
|
|
||
| def test_name_only_errors(self, pytester: pytest.Pytester) -> None: | ||
| p = pytester.makepyfile( | ||
| test_error=""" | ||
| import pytest | ||
| @pytest.fixture | ||
| def bad_fixture(): | ||
| raise RuntimeError("error in fixture") | ||
| def test_error(bad_fixture): | ||
| pass | ||
| """ | ||
| ) | ||
| result = pytester.runpytest(p, "--name-only") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "=* ERRORS *=", | ||
| "ERROR at setup of test_error", | ||
| "=* short test summary info *=", | ||
| "ERROR test_error.py::test_error - RuntimeError: error in fixture", | ||
| ] | ||
| ) | ||
| output = result.stdout.str() | ||
| errors_part = output.split("ERRORS")[1].split("short test summary info")[0] | ||
| assert "ERROR at setup of test_error" in errors_part | ||
| assert "RuntimeError: error in fixture" not in errors_part | ||
|
|
||
| def test_name_only_collection_error(self, pytester: pytest.Pytester) -> None: | ||
| pytester.makepyfile( | ||
| """ | ||
| def test_syntax(): | ||
| assert | ||
| """ | ||
| ) | ||
| result = pytester.runpytest("--name-only") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "=* ERRORS *=", | ||
| "ERROR collecting test_name_only_collection_error.py", | ||
| "=* short test summary info *=", | ||
| "ERROR test_name_only_collection_error.py", | ||
| ] | ||
| ) | ||
| output = result.stdout.str() | ||
| errors_part = output.split("ERRORS")[1].split("short test summary info")[0] | ||
| assert "ERROR collecting test_name_only_collection_error.py" in errors_part | ||
| assert "SyntaxError" not in errors_part | ||
|
|
||
| def test_name_only_with_tb_line(self, pytester: pytest.Pytester) -> None: | ||
| pytester.makepyfile( | ||
| """ | ||
| def test_fail(): | ||
| assert False | ||
| """ | ||
| ) | ||
| result = pytester.runpytest("--name-only", "--tb=line") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "=* FAILURES *=", | ||
| "test_fail", | ||
| ] | ||
| ) | ||
| output = result.stdout.str() | ||
| failures_part = output.split("FAILURES")[1].split("short test summary info")[0] | ||
| assert "test_fail" in failures_part | ||
| assert "assert False" not in failures_part | ||
|
|
||
| def test_name_only_with_verbose(self, pytester: pytest.Pytester) -> None: | ||
| pytester.makepyfile( | ||
| """ | ||
| def test_fail(): | ||
| assert False | ||
| """ | ||
| ) | ||
| result = pytester.runpytest("--name-only", "-v") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "=* FAILURES *=", | ||
| "test_fail", | ||
| "=* short test summary info *=", | ||
| ] | ||
| ) | ||
| output = result.stdout.str() | ||
| failures_part = output.split("FAILURES")[1].split("short test summary info")[0] | ||
| assert "test_fail" in failures_part | ||
| assert "assert False" not in failures_part | ||
|
|
||
| def test_name_only_with_show_capture_no(self, pytester: pytest.Pytester) -> None: | ||
| pytester.makepyfile( | ||
| """ | ||
| def test_fail(): | ||
| print("captured output") | ||
| assert False | ||
| """ | ||
| ) | ||
| result = pytester.runpytest("--name-only", "--show-capture=no") | ||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| "=* FAILURES *=", | ||
| "test_fail", | ||
| "=* short test summary info *=", | ||
| ] | ||
| ) | ||
| output = result.stdout.str() | ||
| failures_part = output.split("FAILURES")[1].split("short test summary info")[0] | ||
| assert "test_fail" in failures_part | ||
| assert "assert False" not in failures_part | ||
| assert "captured output" not in failures_part | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --tb=line case doesn't fully honor --name-only intent. The crash line message is still displayed