From e04d9ff80be855164799bb315d23ca611c4b10f4 Mon Sep 17 00:00:00 2001 From: aostr Date: Sat, 25 Jun 2016 18:16:13 +0200 Subject: [PATCH 1/3] * 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. --- AUTHORS | 1 + CHANGELOG.rst | 4 ++++ _pytest/terminal.py | 13 +++++++++++-- testing/test_config.py | 2 +- testing/test_terminal.py | 14 ++++++++++++-- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index c35e6658739..462dc71e673 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,6 +8,7 @@ Alexei Kozlenok Anatoly Bubenkoff Andreas Zeidler Andy Freeland +Andrzej Ostrowski Anthon van der Neut Armin Rigo Aron Curzon diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e7371a0217f..af7c6db9572 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 + flag ``--disable-pytest-warnings`` to explicitly disable the warnings summary. + This change resolves the (`#1668`_). + * Renamed the pytest ``pdb`` module (plugin) into ``debugging``. * diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 825f553ef2c..3344203d91f 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -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.") + "(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).") @@ -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': diff --git a/testing/test_config.py b/testing/test_config.py index fe06540173e..c90555756df 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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() result = testdir.runpytest("-rw") result.stdout.fnmatch_lines(""" diff --git a/testing/test_terminal.py b/testing/test_terminal.py index be5749c96d2..bda5e858cfd 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -591,6 +591,7 @@ def test_getreportopt(): class config: class option: reportchars = "" + disablepytestwarnings = True config.option.report = "xfailed" assert getreportopt(config) == "x" @@ -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(""" From 1ce467006262a1369474919ca13b0c5831652cdc Mon Sep 17 00:00:00 2001 From: aostr Date: Sun, 26 Jun 2016 06:46:09 +0200 Subject: [PATCH 2/3] * removed tailing whitespaces --- _pytest/terminal.py | 2 +- testing/test_terminal.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 3344203d91f..0eb3696c476 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -26,7 +26,7 @@ def pytest_addoption(parser): "(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, + group._addoption('--disable-pytest-warnings', default=False, dest='disablepytestwarnings', action='store_true', help='disable warnings summary, overrides -r w flag') group._addoption('-l', '--showlocals', diff --git a/testing/test_terminal.py b/testing/test_terminal.py index bda5e858cfd..96ed80e08c6 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -613,7 +613,7 @@ class option: assert getreportopt(config) == "sfxw" config.option.reportchars = "sfxw" - config.option.disablepytestwarnings = False + config.option.disablepytestwarnings = False assert getreportopt(config) == "sfxw" From b4e0fabf93adf533a987b1fc3b567030fce30414 Mon Sep 17 00:00:00 2001 From: aostr Date: Sun, 26 Jun 2016 06:52:36 +0200 Subject: [PATCH 3/3] * added missing link to the referenced issue --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index af7c6db9572..eeb6ca66c68 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -53,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