Skip to content

Commit

Permalink
turn RecordedWarning into a namedtuple
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Oct 19, 2016
1 parent 427cee1 commit ce66923
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 5 additions & 10 deletions _pytest/recwarn.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
""" recording warnings during test function execution. """

import inspect

import _pytest._code
import py
import sys
import warnings
import pytest
from collections import namedtuple


@pytest.yield_fixture
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions testing/test_recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def test_record(self):
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)
Expand Down

0 comments on commit ce66923

Please sign in to comment.