Fix warnings summary header appearing twice
Ref: https://github.com/pytest-dev/pytest/pull/4450#discussion_r236017645 Ref: https://github.com/pytest-dev/pytest/pull/4399
This commit is contained in:
parent
16b15af624
commit
be3b8fc9c1
|
@ -33,8 +33,6 @@ Running pytest now produces this output::
|
||||||
$REGENDOC_TMPDIR/test_show_warnings.py:4: UserWarning: api v1, should use functions from v2
|
$REGENDOC_TMPDIR/test_show_warnings.py:4: UserWarning: api v1, should use functions from v2
|
||||||
warnings.warn(UserWarning("api v1, should use functions from v2"))
|
warnings.warn(UserWarning("api v1, should use functions from v2"))
|
||||||
|
|
||||||
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
|
||||||
========================= warnings summary (final) =========================
|
|
||||||
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
||||||
=================== 1 passed, 1 warnings in 0.12 seconds ===================
|
=================== 1 passed, 1 warnings in 0.12 seconds ===================
|
||||||
|
|
||||||
|
@ -358,8 +356,6 @@ defines an ``__init__`` constructor, as this prevents the class from being insta
|
||||||
$REGENDOC_TMPDIR/test_pytest_warnings.py:1: PytestWarning: cannot collect test class 'Test' because it has a __init__ constructor
|
$REGENDOC_TMPDIR/test_pytest_warnings.py:1: PytestWarning: cannot collect test class 'Test' because it has a __init__ constructor
|
||||||
class Test:
|
class Test:
|
||||||
|
|
||||||
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
|
||||||
========================= warnings summary (final) =========================
|
|
||||||
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
||||||
1 warnings in 0.12 seconds
|
1 warnings in 0.12 seconds
|
||||||
|
|
||||||
|
|
|
@ -422,8 +422,6 @@ additionally it is possible to copy examples for an example folder before runnin
|
||||||
$REGENDOC_TMPDIR/test_example.py:4: PytestExperimentalApiWarning: testdir.copy_example is an experimental api that may change over time
|
$REGENDOC_TMPDIR/test_example.py:4: PytestExperimentalApiWarning: testdir.copy_example is an experimental api that may change over time
|
||||||
testdir.copy_example("test_example.py")
|
testdir.copy_example("test_example.py")
|
||||||
|
|
||||||
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
|
||||||
========================= warnings summary (final) =========================
|
|
||||||
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
-- Docs: https://docs.pytest.org/en/latest/warnings.html
|
||||||
=================== 2 passed, 1 warnings in 0.12 seconds ===================
|
=================== 2 passed, 1 warnings in 0.12 seconds ===================
|
||||||
|
|
||||||
|
|
|
@ -734,6 +734,8 @@ class TerminalReporter(object):
|
||||||
else:
|
else:
|
||||||
warnings = all_warnings
|
warnings = all_warnings
|
||||||
self._already_displayed_warnings = len(warnings)
|
self._already_displayed_warnings = len(warnings)
|
||||||
|
if not warnings:
|
||||||
|
return
|
||||||
|
|
||||||
grouped = itertools.groupby(
|
grouped = itertools.groupby(
|
||||||
warnings, key=lambda wr: wr.get_location(self.config)
|
warnings, key=lambda wr: wr.get_location(self.config)
|
||||||
|
|
|
@ -1094,7 +1094,34 @@ def test_terminal_summary_warnings_are_displayed(testdir):
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert "None" not in result.stdout.str()
|
assert "None" not in result.stdout.str()
|
||||||
assert result.stdout.str().count("warning_from_test") == 1
|
stdout = result.stdout.str()
|
||||||
|
assert stdout.count("warning_from_test") == 1
|
||||||
|
assert stdout.count("=== warnings summary ") == 2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.filterwarnings("default")
|
||||||
|
def test_terminal_summary_warnings_header_once(testdir):
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_failure():
|
||||||
|
import warnings
|
||||||
|
warnings.warn("warning_from_" + "test")
|
||||||
|
assert 0
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest("-ra")
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
"*= warnings summary =*",
|
||||||
|
"*warning_from_test*",
|
||||||
|
"*= short test summary info =*",
|
||||||
|
"*== 1 failed, 1 warnings in *",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
assert "None" not in result.stdout.str()
|
||||||
|
stdout = result.stdout.str()
|
||||||
|
assert stdout.count("warning_from_test") == 1
|
||||||
|
assert stdout.count("=== warnings summary ") == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
Loading…
Reference in New Issue