Skip to content

Commit e04d9ff

Browse files
author
aostr
committed
* now showing pytest warnings summary by default.
* added ``--disable-pytest-warnings` flag to let users disable the warnings summary. * extended/changed unit tests for the changes in the pytest core.
1 parent 9a5224e commit e04d9ff

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Alexei Kozlenok
88
Anatoly Bubenkoff
99
Andreas Zeidler
1010
Andy Freeland
11+
Andrzej Ostrowski
1112
Anthon van der Neut
1213
Armin Rigo
1314
Aron Curzon

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
Thanks `@bagerard`_ for reporting (`#1503`_). Thanks to `@davehunt`_ and
3737
`@tomviner`_ for PR.
3838

39+
* Whitelisted pytest warnings to show up warnings summary by default. Added a new
40+
flag ``--disable-pytest-warnings`` to explicitly disable the warnings summary.
41+
This change resolves the (`#1668`_).
42+
3943
* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.
4044

4145
*

_pytest/terminal.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ def pytest_addoption(parser):
2020
group._addoption('-q', '--quiet', action="count",
2121
dest="quiet", default=0, help="decrease verbosity."),
2222
group._addoption('-r',
23-
action="store", dest="reportchars", default=None, metavar="chars",
23+
action="store", dest="reportchars", default='', metavar="chars",
2424
help="show extra test summary info as specified by chars (f)ailed, "
2525
"(E)error, (s)skipped, (x)failed, (X)passed (w)pytest-warnings "
26-
"(p)passed, (P)passed with output, (a)all except pP.")
26+
"(p)passed, (P)passed with output, (a)all except pP. "
27+
"The pytest warnings are displayed at all times except when "
28+
"--disable-pytest-warnings is set")
29+
group._addoption('--disable-pytest-warnings', default=False,
30+
dest='disablepytestwarnings', action='store_true',
31+
help='disable warnings summary, overrides -r w flag')
2732
group._addoption('-l', '--showlocals',
2833
action="store_true", dest="showlocals", default=False,
2934
help="show locals in tracebacks (disabled by default).")
@@ -66,6 +71,10 @@ def getreportopt(config):
6671
elif setting == "xfailed":
6772
reportopts += "x"
6873
reportchars = config.option.reportchars
74+
if not config.option.disablepytestwarnings and 'w' not in reportchars:
75+
reportchars += 'w'
76+
elif config.option.disablepytestwarnings and 'w' in reportchars:
77+
reportchars = reportchars.replace('w', '')
6978
if reportchars:
7079
for char in reportchars:
7180
if char not in reportopts and char != 'a':

testing/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def test_hello(fix):
519519
""")
520520
result = testdir.runpytest()
521521
assert result.parseoutcomes()["pytest-warnings"] > 0
522-
assert "hello" not in result.stdout.str()
522+
assert "hello" in result.stdout.str()
523523

524524
result = testdir.runpytest("-rw")
525525
result.stdout.fnmatch_lines("""

testing/test_terminal.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ def test_getreportopt():
591591
class config:
592592
class option:
593593
reportchars = ""
594+
disablepytestwarnings = True
594595
config.option.report = "xfailed"
595596
assert getreportopt(config) == "x"
596597

@@ -601,12 +602,21 @@ class option:
601602
assert getreportopt(config) == "sx"
602603

603604
config.option.report = "skipped"
604-
config.option.reportchars = "sf"
605+
config.option.reportchars = "sfw"
605606
assert getreportopt(config) == "sf"
606607

607-
config.option.reportchars = "sfx"
608+
config.option.reportchars = "sfxw"
608609
assert getreportopt(config) == "sfx"
609610

611+
config.option.reportchars = "sfx"
612+
config.option.disablepytestwarnings = False
613+
assert getreportopt(config) == "sfxw"
614+
615+
config.option.reportchars = "sfxw"
616+
config.option.disablepytestwarnings = False
617+
assert getreportopt(config) == "sfxw"
618+
619+
610620
def test_terminalreporter_reportopt_addopts(testdir):
611621
testdir.makeini("[pytest]\naddopts=-rs")
612622
testdir.makepyfile("""

0 commit comments

Comments
 (0)