Skip to content

Commit

Permalink
terminal: default to fE with -r (reportchars)
Browse files Browse the repository at this point in the history
Adds handling of `N` to reset `reportchars`, which can be used to get
the old behavior (`-rN`), and also allows for an alternative to
`--disable-warnings` (pytest-dev#5066),
since `w` was included by default (without `--disable-warnings`).

Fixes pytest-dev#6454
  • Loading branch information
blueyed committed Jan 22, 2020
1 parent 2f0d0fb commit 5fe1fdf
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog/6454.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed default for `-r` to `fE`, which displays failures and errors in the :ref:`short test summary <pytest.detailed_failed_tests_usage>`. `-rN` can be used to disable it (the old behavior).
8 changes: 6 additions & 2 deletions doc/en/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ option you make sure a trace is shown.
Detailed summary report
-----------------------



The ``-r`` flag can be used to display a "short test summary info" at the end of the test session,
making it easy in large test suites to get a clear picture of all failures, skips, xfails, etc.

It defaults to ``fE`` to list failures and errors.

Example:

.. code-block:: python
Expand Down Expand Up @@ -261,8 +261,12 @@ Here is the full list of available characters that can be used:
- ``X`` - xpassed
- ``p`` - passed
- ``P`` - passed with output

Special characters for (de)selection of groups:

- ``a`` - all except ``pP``
- ``A`` - all
- ``N`` - none, this can be used to display nothing (since ``fE`` is the default)

More than one character can be used, so for example to only see failed and skipped tests, you can execute:

Expand Down
12 changes: 8 additions & 4 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

REPORT_COLLECTING_RESOLUTION = 0.5

_REPORTCHARS_DEFAULT = "fE"


class MoreQuietAction(argparse.Action):
"""
Expand Down Expand Up @@ -88,12 +90,13 @@ def pytest_addoption(parser):
"-r",
action="store",
dest="reportchars",
default="",
default=_REPORTCHARS_DEFAULT,
metavar="chars",
help="show extra test summary info as specified by chars: (f)ailed, "
"(E)rror, (s)kipped, (x)failed, (X)passed, "
"(p)assed, (P)assed with output, (a)ll except passed (p/P), or (A)ll. "
"(w)arnings are enabled by default (see --disable-warnings).",
"(w)arnings are enabled by default (see --disable-warnings), "
"'N' can be used to reset the list. (default: 'fE').",
)
group._addoption(
"--disable-warnings",
Expand Down Expand Up @@ -169,7 +172,7 @@ def getreportopt(config: Config) -> str:
reportopts = ""
reportchars = config.option.reportchars
if not config.option.disable_warnings and "w" not in reportchars:
reportchars += "w"
reportchars = "w" + reportchars
elif config.option.disable_warnings and "w" in reportchars:
reportchars = reportchars.replace("w", "")
aliases = {"F", "S"}
Expand All @@ -181,7 +184,8 @@ def getreportopt(config: Config) -> str:
reportopts = "sxXwEf"
elif char == "A":
reportopts = "PpsxXwEf"
break
elif char == "N":
reportopts = ""
elif char not in reportopts:
reportopts += char
return reportopts
Expand Down
49 changes: 37 additions & 12 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,9 @@ def test():
def test_fail_extra_reporting(testdir, monkeypatch):
monkeypatch.setenv("COLUMNS", "80")
testdir.makepyfile("def test_this(): assert 0, 'this_failed' * 100")
result = testdir.runpytest()
result = testdir.runpytest("-rN")
result.stdout.no_fnmatch_line("*short test summary*")
result = testdir.runpytest("-rf")
result = testdir.runpytest()
result.stdout.fnmatch_lines(
[
"*test summary*",
Expand Down Expand Up @@ -918,38 +918,63 @@ def test_this(i):


def test_getreportopt():
from _pytest.terminal import _REPORTCHARS_DEFAULT

class Config:
class Option:
reportchars = ""
disable_warnings = True
reportchars = _REPORTCHARS_DEFAULT
disable_warnings = False

option = Option()

config = Config()

assert _REPORTCHARS_DEFAULT == "fE"

# Default.
assert getreportopt(config) == "wfE"

config.option.reportchars = "sf"
assert getreportopt(config) == "sf"
assert getreportopt(config) == "wsf"

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

config.option.reportchars = "a"
assert getreportopt(config) == "sxXwEf"

config.option.reportchars = "N"
assert getreportopt(config) == ""

config.option.reportchars = "NwfE"
assert getreportopt(config) == "wfE"

config.option.reportchars = "NfENx"
assert getreportopt(config) == "x"

# Now with --disable-warnings.
config.option.disable_warnings = False
config.option.disable_warnings = True
config.option.reportchars = "a"
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
assert getreportopt(config) == "sxXwEf"

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

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

config.option.reportchars = "a"
assert getreportopt(config) == "sxXwEf" # NOTE: "w" included!
assert getreportopt(config) == "sxXwEf"

config.option.reportchars = "A"
assert getreportopt(config) == "PpsxXwEf"

config.option.reportchars = "AN"
assert getreportopt(config) == ""

config.option.reportchars = "NwfE"
assert getreportopt(config) == "fE"


def test_terminalreporter_reportopt_addopts(testdir):
testdir.makeini("[pytest]\naddopts=-rs")
Expand Down Expand Up @@ -1065,7 +1090,7 @@ def test_func():
)
for tbopt in ["long", "short", "no"]:
print("testing --tb=%s..." % tbopt)
result = testdir.runpytest("--tb=%s" % tbopt)
result = testdir.runpytest("-rN", "--tb=%s" % tbopt)
s = result.stdout.str()
if tbopt == "long":
assert "print(6*7)" in s
Expand Down

0 comments on commit 5fe1fdf

Please sign in to comment.