Change warning output
This commit is contained in:
parent
82785fcd40
commit
e24081bf76
|
@ -24,9 +24,9 @@ def pytest_addoption(parser):
|
|||
help="show extra test summary info as specified by chars (f)ailed, "
|
||||
"(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")
|
||||
group._addoption('--disable-pytest-warnings', default=False,
|
||||
"Warnings are displayed at all times except when "
|
||||
"--disable-warnings is set")
|
||||
group._addoption('--disable-warnings', '--disable-pytest-warnings', default=False,
|
||||
dest='disablepytestwarnings', action='store_true',
|
||||
help='disable warnings summary, overrides -r w flag')
|
||||
group._addoption('-l', '--showlocals',
|
||||
|
@ -441,10 +441,14 @@ class TerminalReporter(object):
|
|||
warnings = self.stats.get("warnings")
|
||||
if not warnings:
|
||||
return
|
||||
self.write_sep("=", "pytest-warning summary")
|
||||
self.write_sep("=", "warnings summary")
|
||||
for w in warnings:
|
||||
self._tw.line("W%s %s %s" % (w.code,
|
||||
w.fslocation, w.message))
|
||||
msg = ''
|
||||
if w.fslocation:
|
||||
msg += str(w.fslocation) + ' '
|
||||
msg += w.message
|
||||
self._tw.line(msg)
|
||||
self._tw.line('-- Docs: http://doc.pytest.org/en/latest/warnings.html')
|
||||
|
||||
def summary_passes(self):
|
||||
if self.config.option.tbstyle != "no":
|
||||
|
@ -546,8 +550,7 @@ def flatten(l):
|
|||
|
||||
def build_summary_stats_line(stats):
|
||||
keys = ("failed passed skipped deselected "
|
||||
"xfailed xpassed warnings error").split()
|
||||
key_translation = {'warnings': 'pytest-warnings'}
|
||||
"xfailed xpassed warnings error").split()
|
||||
unknown_key_seen = False
|
||||
for key in stats.keys():
|
||||
if key not in keys:
|
||||
|
@ -558,8 +561,7 @@ def build_summary_stats_line(stats):
|
|||
for key in keys:
|
||||
val = stats.get(key, None)
|
||||
if val:
|
||||
key_name = key_translation.get(key, key)
|
||||
parts.append("%d %s" % (len(val), key_name))
|
||||
parts.append("%d %s" % (len(val), key))
|
||||
|
||||
if parts:
|
||||
line = ", ".join(parts)
|
||||
|
|
|
@ -55,11 +55,5 @@ def pytest_runtest_call(item):
|
|||
for warning in log:
|
||||
msg = warnings.formatwarning(
|
||||
warning.message, warning.category,
|
||||
os.path.relpath(warning.filename), warning.lineno, warning.line)
|
||||
fslocation = getattr(item, "location", None)
|
||||
if fslocation is None:
|
||||
fslocation = getattr(item, "fspath", None)
|
||||
else:
|
||||
fslocation = "%s:%s" % fslocation[:2]
|
||||
fslocation = "in %s the following warning was recorded:\n" % fslocation
|
||||
item.config.warn("W0", msg, fslocation=fslocation)
|
||||
warning.filename, warning.lineno, warning.line)
|
||||
item.config.warn("W0", msg, fslocation=None)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import pytest
|
||||
|
||||
|
||||
WARNINGS_SUMMARY_HEADER = 'warnings summary'
|
||||
|
||||
@pytest.fixture
|
||||
def pyfile_with_warnings(testdir):
|
||||
testdir.makepyfile('''
|
||||
|
@ -14,16 +16,14 @@ def pyfile_with_warnings(testdir):
|
|||
def test_normal_flow(testdir, pyfile_with_warnings):
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines([
|
||||
'*== pytest-warning summary ==*',
|
||||
'*== %s ==*' % WARNINGS_SUMMARY_HEADER,
|
||||
|
||||
'WW0 in *test_normal_flow.py:1 the following warning was recorded:',
|
||||
' test_normal_flow.py:3: PendingDeprecationWarning: functionality is pending deprecation',
|
||||
'*test_normal_flow.py:3: PendingDeprecationWarning: functionality is pending deprecation',
|
||||
' warnings.warn(PendingDeprecationWarning("functionality is pending deprecation"))',
|
||||
|
||||
'WW0 in *test_normal_flow.py:1 the following warning was recorded:',
|
||||
' test_normal_flow.py:4: DeprecationWarning: functionality is deprecated',
|
||||
'*test_normal_flow.py:4: DeprecationWarning: functionality is deprecated',
|
||||
' warnings.warn(DeprecationWarning("functionality is deprecated"))',
|
||||
'* 1 passed, 2 pytest-warnings*',
|
||||
'* 1 passed, 2 warnings*',
|
||||
])
|
||||
|
||||
|
||||
|
@ -56,5 +56,5 @@ def test_ignore(testdir, pyfile_with_warnings, method):
|
|||
result.stdout.fnmatch_lines([
|
||||
'* 1 passed in *',
|
||||
])
|
||||
assert 'pytest-warning summary' not in result.stdout.str()
|
||||
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
|
||||
|
||||
|
|
Loading…
Reference in New Issue