Merge pull request #1726 from nicoddemus/warnings-displayed-by-default

Warnings displayed by default
This commit is contained in:
Bruno Oliveira 2016-07-13 19:33:49 -03:00 committed by GitHub
commit 1fb09d9dd5
5 changed files with 33 additions and 6 deletions

View File

@ -9,6 +9,7 @@ Alexei Kozlenok
Anatoly Bubenkoff Anatoly Bubenkoff
Andreas Zeidler Andreas Zeidler
Andy Freeland Andy Freeland
Andrzej Ostrowski
Anthon van der Neut Anthon van der Neut
Antony Lee Antony Lee
Armin Rigo Armin Rigo

View File

@ -160,6 +160,10 @@ time or change existing behaviors in order to make them less surprising/more use
parametrize. parametrize.
Thanks `@palaviv`_ for the complete PR (`#1474`_). 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 * Make ImportError during collection more explicit by reminding
the user to check the name of the test module/package(s) (`#1426`_). the user to check the name of the test module/package(s) (`#1426`_).
Thanks `@omarkohl`_ for the complete PR (`#1520`_). Thanks `@omarkohl`_ for the complete PR (`#1520`_).
@ -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 * Fix internal error issue when the ``method`` argument is missing for
``teardown_method()`` (`#1605`_). ``teardown_method()`` (`#1605`_).
* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.
* Fix exception visualization in case the current working directory (CWD) gets * Fix exception visualization in case the current working directory (CWD) gets
deleted during testing (`#1235`_). Thanks `@bukzor`_ for reporting. PR by deleted during testing (`#1235`_). Thanks `@bukzor`_ for reporting. PR by
`@marscher`_. `@marscher`_.
@ -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 .. _#1618: https://github.com/pytest-dev/pytest/issues/1618
.. _#1619: https://github.com/pytest-dev/pytest/issues/1619 .. _#1619: https://github.com/pytest-dev/pytest/issues/1619
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626 .. _#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 .. _#1627: https://github.com/pytest-dev/pytest/pull/1627
.. _#1628: https://github.com/pytest-dev/pytest/pull/1628 .. _#1628: https://github.com/pytest-dev/pytest/pull/1628
.. _#1629: https://github.com/pytest-dev/pytest/issues/1629 .. _#1629: https://github.com/pytest-dev/pytest/issues/1629

View File

@ -20,10 +20,15 @@ def pytest_addoption(parser):
group._addoption('-q', '--quiet', action="count", group._addoption('-q', '--quiet', action="count",
dest="quiet", default=0, help="decrease verbosity."), dest="quiet", default=0, help="decrease verbosity."),
group._addoption('-r', 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, " help="show extra test summary info as specified by chars (f)ailed, "
"(E)error, (s)skipped, (x)failed, (X)passed (w)pytest-warnings " "(E)error, (s)skipped, (x)failed, (X)passed, "
"(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', group._addoption('-l', '--showlocals',
action="store_true", dest="showlocals", default=False, action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default).") help="show locals in tracebacks (disabled by default).")
@ -52,6 +57,10 @@ def pytest_configure(config):
def getreportopt(config): def getreportopt(config):
reportopts = "" reportopts = ""
reportchars = config.option.reportchars 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: if reportchars:
for char in reportchars: for char in reportchars:
if char not in reportopts and char != 'a': if char not in reportopts and char != 'a':

View File

@ -539,11 +539,11 @@ class TestWarning:
def test_hello(fix): def test_hello(fix):
pass pass
""") """)
result = testdir.runpytest() result = testdir.runpytest("--disable-pytest-warnings")
assert result.parseoutcomes()["pytest-warnings"] > 0 assert result.parseoutcomes()["pytest-warnings"] > 0
assert "hello" not in result.stdout.str() assert "hello" not in result.stdout.str()
result = testdir.runpytest("-rw") result = testdir.runpytest()
result.stdout.fnmatch_lines(""" result.stdout.fnmatch_lines("""
===*pytest-warning summary*=== ===*pytest-warning summary*===
*WT1*test_warn_on_test_item*:5*hello* *WT1*test_warn_on_test_item*:5*hello*

View File

@ -590,13 +590,23 @@ def test_getreportopt():
class config: class config:
class option: class option:
reportchars = "" reportchars = ""
disablepytestwarnings = True
config.option.reportchars = "sf" config.option.reportchars = "sf"
assert getreportopt(config) == "sf" assert getreportopt(config) == "sf"
config.option.reportchars = "sfx" config.option.reportchars = "sfxw"
assert getreportopt(config) == "sfx" 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): def test_terminalreporter_reportopt_addopts(testdir):
testdir.makeini("[pytest]\naddopts=-rs") testdir.makeini("[pytest]\naddopts=-rs")
testdir.makepyfile(""" testdir.makepyfile("""