Fix test_recwarn in Python 3.6

No longer test for implementation details of recwarn since warnings.catch_warnings has changed
significantly in 3.6.
This commit is contained in:
Bruno Oliveira 2017-03-13 19:52:35 -03:00
parent 22864b75ee
commit 3c07072bfd
1 changed files with 2 additions and 10 deletions

View File

@ -8,25 +8,19 @@ from _pytest.recwarn import WarningsRecorder
def test_recwarn_functional(testdir): def test_recwarn_functional(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
import warnings import warnings
oldwarn = warnings.showwarning
def test_method(recwarn): def test_method(recwarn):
assert warnings.showwarning != oldwarn
warnings.warn("hello") warnings.warn("hello")
warn = recwarn.pop() warn = recwarn.pop()
assert isinstance(warn.message, UserWarning) assert isinstance(warn.message, UserWarning)
def test_finalized():
assert warnings.showwarning == oldwarn
""") """)
res = reprec.countoutcomes() res = reprec.countoutcomes()
assert tuple(res) == (2, 0, 0), res assert tuple(res) == (1, 0, 0), res
class TestWarningsRecorderChecker(object): class TestWarningsRecorderChecker(object):
def test_recording(self, recwarn): def test_recording(self):
showwarning = py.std.warnings.showwarning
rec = WarningsRecorder() rec = WarningsRecorder()
with rec: with rec:
assert py.std.warnings.showwarning != showwarning
assert not rec.list assert not rec.list
py.std.warnings.warn_explicit("hello", UserWarning, "xyz", 13) py.std.warnings.warn_explicit("hello", UserWarning, "xyz", 13)
assert len(rec.list) == 1 assert len(rec.list) == 1
@ -40,8 +34,6 @@ class TestWarningsRecorderChecker(object):
assert l is rec.list assert l is rec.list
pytest.raises(AssertionError, "rec.pop()") pytest.raises(AssertionError, "rec.pop()")
assert showwarning == py.std.warnings.showwarning
def test_typechecking(self): def test_typechecking(self):
from _pytest.recwarn import WarningsChecker from _pytest.recwarn import WarningsChecker
with pytest.raises(TypeError): with pytest.raises(TypeError):