Skip to content
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

showing pytest warnings summary by default. #1672

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Alexei Kozlenok
Anatoly Bubenkoff
Andreas Zeidler
Andy Freeland
Andrzej Ostrowski
Anthon van der Neut
Armin Rigo
Aron Curzon
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
Thanks `@bagerard`_ for reporting (`#1503`_). Thanks to `@davehunt`_ and
`@tomviner`_ for PR.

* Whitelisted pytest warnings to show up warnings summary by default. Added a new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Whitelisted pytest warnings" seems confusing - it sounds like some warnings are on a whitelist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rephrase this once I get to a place with a stable internet connection :)

flag ``--disable-pytest-warnings`` to explicitly disable the warnings summary.
This change resolves the (`#1668`_).

* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.

*
Expand All @@ -49,6 +53,7 @@
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
.. _#1668: https://github.com/pytest-dev/pytest/issues/1668

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
Expand Down
13 changes: 11 additions & 2 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ def pytest_addoption(parser):
group._addoption('-q', '--quiet', action="count",
dest="quiet", default=0, help="decrease verbosity."),
group._addoption('-r',
action="store", dest="reportchars", default=None, metavar="chars",
action="store", dest="reportchars", default='', metavar="chars",
help="show extra test summary info as specified by chars (f)ailed, "
"(E)error, (s)skipped, (x)failed, (X)passed (w)pytest-warnings "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, but also I think we should remove (w)pytest-warnings from the list as it no longer has an effect.

"(p)passed, (P)passed with output, (a)all except pP.")
"(p)passed, (P)passed with output, (a)all except pP. "
"The pytest warnings are displayed at all times except when "
"--disable-pytest-warnings is set")
group._addoption('--disable-pytest-warnings', default=False,
dest='disablepytestwarnings', action='store_true',
help='disable warnings summary, overrides -r w flag')
group._addoption('-l', '--showlocals',
action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default).")
Expand Down Expand Up @@ -66,6 +71,10 @@ def getreportopt(config):
elif setting == "xfailed":
reportopts += "x"
reportchars = config.option.reportchars
if not config.option.disablepytestwarnings and 'w' not in reportchars:
reportchars += 'w'
elif config.option.disablepytestwarnings and 'w' in reportchars:
reportchars = reportchars.replace('w', '')
if reportchars:
for char in reportchars:
if char not in reportopts and char != 'a':
Expand Down
2 changes: 1 addition & 1 deletion testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def test_hello(fix):
""")
result = testdir.runpytest()
assert result.parseoutcomes()["pytest-warnings"] > 0
assert "hello" not in result.stdout.str()
assert "hello" in result.stdout.str()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code needs to revert the change in the assertion and pass --disable-pytest-warnings to testdir.runpytest in line 520.


result = testdir.runpytest("-rw")
Copy link
Member

@nicoddemus nicoddemus Jun 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense for this call to no longer pass anything, and the warning should appear in the output normally.

result.stdout.fnmatch_lines("""
Expand Down
14 changes: 12 additions & 2 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ def test_getreportopt():
class config:
class option:
reportchars = ""
disablepytestwarnings = True
config.option.report = "xfailed"
assert getreportopt(config) == "x"

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

config.option.report = "skipped"
config.option.reportchars = "sf"
config.option.reportchars = "sfw"
assert getreportopt(config) == "sf"

config.option.reportchars = "sfx"
config.option.reportchars = "sfxw"
assert getreportopt(config) == "sfx"

config.option.reportchars = "sfx"
config.option.disablepytestwarnings = False
assert getreportopt(config) == "sfxw"

config.option.reportchars = "sfxw"
config.option.disablepytestwarnings = False
assert getreportopt(config) == "sfxw"


def test_terminalreporter_reportopt_addopts(testdir):
testdir.makeini("[pytest]\naddopts=-rs")
testdir.makepyfile("""
Expand Down