parent
377e649e61
commit
e9668d75b8
|
@ -1,5 +1,4 @@
|
||||||
""" recording warnings during test function execution. """
|
""" recording warnings during test function execution. """
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
@ -7,6 +6,7 @@ import py
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
import pytest
|
import pytest
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
|
@ -110,15 +110,10 @@ def warns(expected_warning, *args, **kwargs):
|
||||||
return func(*args[1:], **kwargs)
|
return func(*args[1:], **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class RecordedWarning(object):
|
RecordedWarning = namedtuple('RecordedWarning', (
|
||||||
def __init__(self, message, category, filename, lineno, file, line):
|
'message', 'category', 'filename', 'lineno', 'file', 'line',
|
||||||
self.message = message
|
))
|
||||||
self.category = category
|
|
||||||
self.filename = filename
|
|
||||||
self.lineno = lineno
|
|
||||||
self.file = file
|
|
||||||
self.line = line
|
|
||||||
|
|
||||||
|
|
||||||
class WarningsRecorder(object):
|
class WarningsRecorder(object):
|
||||||
"""A context manager to record raised warnings.
|
"""A context manager to record raised warnings.
|
||||||
|
|
|
@ -203,6 +203,9 @@ class TestWarns(object):
|
||||||
assert len(record) == 1
|
assert len(record) == 1
|
||||||
assert str(record[0].message) == "user"
|
assert str(record[0].message) == "user"
|
||||||
|
|
||||||
|
print(repr(record[0]))
|
||||||
|
assert str(record[0].message) in repr(record[0])
|
||||||
|
|
||||||
def test_record_only(self):
|
def test_record_only(self):
|
||||||
with pytest.warns(None) as record:
|
with pytest.warns(None) as record:
|
||||||
warnings.warn("user", UserWarning)
|
warnings.warn("user", UserWarning)
|
||||||
|
|
Loading…
Reference in New Issue