diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index a89474c03..0f6f93571 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -1,5 +1,4 @@ """ recording warnings during test function execution. """ - import inspect import _pytest._code @@ -7,6 +6,7 @@ import py import sys import warnings import pytest +from collections import namedtuple @pytest.yield_fixture @@ -110,15 +110,10 @@ def warns(expected_warning, *args, **kwargs): return func(*args[1:], **kwargs) -class RecordedWarning(object): - def __init__(self, message, category, filename, lineno, file, line): - self.message = message - self.category = category - self.filename = filename - self.lineno = lineno - self.file = file - self.line = line - +RecordedWarning = namedtuple('RecordedWarning', ( + 'message', 'category', 'filename', 'lineno', 'file', 'line', +)) + class WarningsRecorder(object): """A context manager to record raised warnings. diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index 87e5846c2..36be5d0d2 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -203,6 +203,9 @@ class TestWarns(object): assert len(record) == 1 assert str(record[0].message) == "user" + print(repr(record[0])) + assert str(record[0].message) in repr(record[0]) + def test_record_only(self): with pytest.warns(None) as record: warnings.warn("user", UserWarning)