Warnings always raised in WarningsRecorder
This ensures that if tests for warnings are run more than once, the warning is still raised as expected.
This commit is contained in:
parent
02e742b7a6
commit
39f1471e93
|
@ -143,10 +143,14 @@ class WarningsRecorder(object):
|
||||||
message, category, filename, lineno, file, line))
|
message, category, filename, lineno, file, line))
|
||||||
|
|
||||||
# still perform old showwarning functionality
|
# still perform old showwarning functionality
|
||||||
self._showwarning(message, category, filename, lineno,
|
self._showwarning(
|
||||||
file=file, line=line)
|
message, category, filename, lineno, file=file, line=line)
|
||||||
|
|
||||||
self._module.showwarning = showwarning
|
self._module.showwarning = showwarning
|
||||||
|
|
||||||
|
# allow the same warning to be raised more than once
|
||||||
|
self._module.simplefilter('always', append=True)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *exc_info):
|
def __exit__(self, *exc_info):
|
||||||
|
|
|
@ -167,3 +167,9 @@ class TestWarns(object):
|
||||||
assert len(record) == 2
|
assert len(record) == 2
|
||||||
assert str(record[0].message) == "user"
|
assert str(record[0].message) == "user"
|
||||||
assert str(record[1].message) == "runtime"
|
assert str(record[1].message) == "runtime"
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('run', [1, 2])
|
||||||
|
def test_doubletest(self, run):
|
||||||
|
"""If a test is run again, the warning should still be raised"""
|
||||||
|
with pytest.warns(RuntimeWarning):
|
||||||
|
warnings.warn("runtime", RuntimeWarning)
|
||||||
|
|
Loading…
Reference in New Issue