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, "
|
help="show extra test summary info as specified by chars (f)ailed, "
|
||||||
"(E)error, (s)skipped, (x)failed, (X)passed, "
|
"(E)error, (s)skipped, (x)failed, (X)passed, "
|
||||||
"(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 "
|
"Warnings are displayed at all times except when "
|
||||||
"--disable-pytest-warnings is set")
|
"--disable-warnings is set")
|
||||||
group._addoption('--disable-pytest-warnings', default=False,
|
group._addoption('--disable-warnings', '--disable-pytest-warnings', default=False,
|
||||||
dest='disablepytestwarnings', action='store_true',
|
dest='disablepytestwarnings', action='store_true',
|
||||||
help='disable warnings summary, overrides -r w flag')
|
help='disable warnings summary, overrides -r w flag')
|
||||||
group._addoption('-l', '--showlocals',
|
group._addoption('-l', '--showlocals',
|
||||||
|
@ -441,10 +441,14 @@ class TerminalReporter(object):
|
||||||
warnings = self.stats.get("warnings")
|
warnings = self.stats.get("warnings")
|
||||||
if not warnings:
|
if not warnings:
|
||||||
return
|
return
|
||||||
self.write_sep("=", "pytest-warning summary")
|
self.write_sep("=", "warnings summary")
|
||||||
for w in warnings:
|
for w in warnings:
|
||||||
self._tw.line("W%s %s %s" % (w.code,
|
msg = ''
|
||||||
w.fslocation, w.message))
|
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):
|
def summary_passes(self):
|
||||||
if self.config.option.tbstyle != "no":
|
if self.config.option.tbstyle != "no":
|
||||||
|
@ -546,8 +550,7 @@ def flatten(l):
|
||||||
|
|
||||||
def build_summary_stats_line(stats):
|
def build_summary_stats_line(stats):
|
||||||
keys = ("failed passed skipped deselected "
|
keys = ("failed passed skipped deselected "
|
||||||
"xfailed xpassed warnings error").split()
|
"xfailed xpassed warnings error").split()
|
||||||
key_translation = {'warnings': 'pytest-warnings'}
|
|
||||||
unknown_key_seen = False
|
unknown_key_seen = False
|
||||||
for key in stats.keys():
|
for key in stats.keys():
|
||||||
if key not in keys:
|
if key not in keys:
|
||||||
|
@ -558,8 +561,7 @@ def build_summary_stats_line(stats):
|
||||||
for key in keys:
|
for key in keys:
|
||||||
val = stats.get(key, None)
|
val = stats.get(key, None)
|
||||||
if val:
|
if val:
|
||||||
key_name = key_translation.get(key, key)
|
parts.append("%d %s" % (len(val), key))
|
||||||
parts.append("%d %s" % (len(val), key_name))
|
|
||||||
|
|
||||||
if parts:
|
if parts:
|
||||||
line = ", ".join(parts)
|
line = ", ".join(parts)
|
||||||
|
|
|
@ -55,11 +55,5 @@ def pytest_runtest_call(item):
|
||||||
for warning in log:
|
for warning in log:
|
||||||
msg = warnings.formatwarning(
|
msg = warnings.formatwarning(
|
||||||
warning.message, warning.category,
|
warning.message, warning.category,
|
||||||
os.path.relpath(warning.filename), warning.lineno, warning.line)
|
warning.filename, warning.lineno, warning.line)
|
||||||
fslocation = getattr(item, "location", None)
|
item.config.warn("W0", msg, fslocation=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)
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
WARNINGS_SUMMARY_HEADER = 'warnings summary'
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pyfile_with_warnings(testdir):
|
def pyfile_with_warnings(testdir):
|
||||||
testdir.makepyfile('''
|
testdir.makepyfile('''
|
||||||
|
@ -14,16 +16,14 @@ def pyfile_with_warnings(testdir):
|
||||||
def test_normal_flow(testdir, pyfile_with_warnings):
|
def test_normal_flow(testdir, pyfile_with_warnings):
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines([
|
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"))',
|
' 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"))',
|
' 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([
|
result.stdout.fnmatch_lines([
|
||||||
'* 1 passed in *',
|
'* 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