From e04d9ff80be855164799bb315d23ca611c4b10f4 Mon Sep 17 00:00:00 2001 From: aostr Date: Sat, 25 Jun 2016 18:16:13 +0200 Subject: [PATCH 1/4] * 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 c35e66587..462dc71e6 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 e7371a021..af7c6db95 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 825f553ef..3344203d9 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 fe0654017..c90555756 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -519,7 +519,7 @@ class TestWarning: """) 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 be5749c96..bda5e858c 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 @@ def test_getreportopt(): 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/4] * 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 3344203d9..0eb3696c4 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 bda5e858c..96ed80e08 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -613,7 +613,7 @@ def test_getreportopt(): 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/4] * added missing link to the referenced issue --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index af7c6db95..eeb6ca66c 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 From 94e4a2dd6787573807dd9115ac71cb7d89c65cb0 Mon Sep 17 00:00:00 2001 From: aostr Date: Tue, 5 Jul 2016 15:22:27 +0200 Subject: [PATCH 4/4] * implemented changes recommended by nicoddemus --- CHANGELOG.rst | 4 ++-- _pytest/terminal.py | 2 +- testing/test_config.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index eeb6ca66c..b3eb6e7e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -36,8 +36,8 @@ 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. +* 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`_). * Renamed the pytest ``pdb`` module (plugin) into ``debugging``. diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 0eb3696c4..ed58c4d2f 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -22,7 +22,7 @@ def pytest_addoption(parser): group._addoption('-r', 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 " + "(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") diff --git a/testing/test_config.py b/testing/test_config.py index c90555756..f6511b8d4 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -517,11 +517,11 @@ class TestWarning: def test_hello(fix): pass """) - result = testdir.runpytest() + result = testdir.runpytest("--disable-pytest-warnings") assert result.parseoutcomes()["pytest-warnings"] > 0 - assert "hello" in result.stdout.str() + 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*