From 6ac638ba876a366a1155c4103da9b1a7014e1586 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 29 Sep 2011 23:44:26 +0200 Subject: [PATCH] add a reportchar for reporting errors, fixes #76 --- _pytest/skipping.py | 10 ++++++---- _pytest/terminal.py | 2 +- testing/test_skipping.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/_pytest/skipping.py b/_pytest/skipping.py index fe69f295e..6a1ddece4 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -169,21 +169,23 @@ def pytest_terminal_summary(terminalreporter): elif char == "X": show_xpassed(terminalreporter, lines) elif char in "fF": - show_failed(terminalreporter, lines) + show_simple(terminalreporter, lines, 'failed', "FAIL %s") elif char in "sS": show_skipped(terminalreporter, lines) + elif char == "E": + show_simple(terminalreporter, lines, 'error', "ERROR %s") if lines: tr._tw.sep("=", "short test summary info") for line in lines: tr._tw.line(line) -def show_failed(terminalreporter, lines): +def show_simple(terminalreporter, lines, stat, format): tw = terminalreporter._tw - failed = terminalreporter.stats.get("failed") + failed = terminalreporter.stats.get(stat) if failed: for rep in failed: pos = rep.nodeid - lines.append("FAIL %s" %(pos, )) + lines.append(format %(pos, )) def show_xfailed(terminalreporter, lines): xfailed = terminalreporter.stats.get("xfailed") diff --git a/_pytest/terminal.py b/_pytest/terminal.py index f8b3244ff..8f1061b22 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -15,7 +15,7 @@ def pytest_addoption(parser): group._addoption('-r', action="store", dest="reportchars", default=None, metavar="chars", help="show extra test summary info as specified by chars (f)ailed, " - "(s)skipped, (x)failed, (X)passed.") + "(E)error, (s)skipped, (x)failed, (X)passed.") group._addoption('-l', '--showlocals', action="store_true", dest="showlocals", default=False, help="show locals in tracebacks (disabled by default).") diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 7bcc8bfb7..e6a6bce0b 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -472,6 +472,21 @@ def test_reportchars(testdir): "SKIP*four*", ]) +def test_reportchars_error(testdir): + testdir.makepyfile( + conftest=""" + def pytest_runtest_teardown(): + assert 0 + """, + test_simple=""" + def test_foo(): + pass + """) + result = testdir.runpytest('-rE') + result.stdout.fnmatch_lines([ + 'ERROR*test_foo*', + ]) + @pytest.mark.xfail("hasattr(sys, 'pypy_version_info')") def test_errors_in_xfail_skip_expressions(testdir): testdir.makepyfile("""