Skip to content

Commit

Permalink
Merge pull request #1726 from nicoddemus/warnings-displayed-by-default
Browse files Browse the repository at this point in the history
Warnings displayed by default
  • Loading branch information
nicoddemus authored Jul 13, 2016
2 parents 6e9ee2b + 1266ebe commit 1fb09d9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Alexei Kozlenok
Anatoly Bubenkoff
Andreas Zeidler
Andy Freeland
Andrzej Ostrowski
Anthon van der Neut
Antony Lee
Armin Rigo
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ time or change existing behaviors in order to make them less surprising/more use
parametrize.
Thanks `@palaviv`_ for the complete PR (`#1474`_).

* Now pytest warnings summary is shown up by default. Added a new flag
``--disable-pytest-warnings`` to explicitly disable the warnings summary.
This change resolves the (`#1668`_).

* Make ImportError during collection more explicit by reminding
the user to check the name of the test module/package(s) (`#1426`_).
Thanks `@omarkohl`_ for the complete PR (`#1520`_).
Expand Down Expand Up @@ -216,6 +220,8 @@ time or change existing behaviors in order to make them less surprising/more use
* Fix internal error issue when the ``method`` argument is missing for
``teardown_method()`` (`#1605`_).

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

* Fix exception visualization in case the current working directory (CWD) gets
deleted during testing (`#1235`_). Thanks `@bukzor`_ for reporting. PR by
`@marscher`_.
Expand Down Expand Up @@ -268,6 +274,7 @@ time or change existing behaviors in order to make them less surprising/more use
.. _#1618: https://github.com/pytest-dev/pytest/issues/1618
.. _#1619: https://github.com/pytest-dev/pytest/issues/1619
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
.. _#1668: https://github.com/pytest-dev/pytest/issues/1668
.. _#1627: https://github.com/pytest-dev/pytest/pull/1627
.. _#1628: https://github.com/pytest-dev/pytest/pull/1628
.. _#1629: https://github.com/pytest-dev/pytest/issues/1629
Expand Down
15 changes: 12 additions & 3 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 "
"(p)passed, (P)passed with output, (a)all except pP.")
"(E)error, (s)skipped, (x)failed, (X)passed, "
"(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 @@ -52,6 +57,10 @@ def mywriter(tags, args):
def getreportopt(config):
reportopts = ""
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
4 changes: 2 additions & 2 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,11 @@ def fix(request):
def test_hello(fix):
pass
""")
result = testdir.runpytest()
result = testdir.runpytest("--disable-pytest-warnings")
assert result.parseoutcomes()["pytest-warnings"] > 0
assert "hello" not in result.stdout.str()

result = testdir.runpytest("-rw")
result = testdir.runpytest()
result.stdout.fnmatch_lines("""
===*pytest-warning summary*===
*WT1*test_warn_on_test_item*:5*hello*
Expand Down
12 changes: 11 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,23 @@ def test_getreportopt():
class config:
class option:
reportchars = ""
disablepytestwarnings = True

config.option.reportchars = "sf"
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

0 comments on commit 1fb09d9

Please sign in to comment.