Use testdir fixture in test_double_test to ensure controlled environment for execution
Because the test relies that two subsequent tests try to use pytest.warns to capture the exact same warning, it is better to use testdir to ensure test execution occurs in the order we expect (which might be different with pytest-xdist or pytest-random for example)
This commit is contained in:
parent
39f1471e93
commit
2bbe709bce
|
@ -168,8 +168,17 @@ class TestWarns(object):
|
|||
assert str(record[0].message) == "user"
|
||||
assert str(record[1].message) == "runtime"
|
||||
|
||||
@pytest.mark.parametrize('run', [1, 2])
|
||||
def test_doubletest(self, run):
|
||||
def test_double_test(self, testdir):
|
||||
"""If a test is run again, the warning should still be raised"""
|
||||
testdir.makepyfile('''
|
||||
import pytest
|
||||
import warnings
|
||||
|
||||
@pytest.mark.parametrize('run', [1, 2])
|
||||
def test(run):
|
||||
with pytest.warns(RuntimeWarning):
|
||||
warnings.warn("runtime", RuntimeWarning)
|
||||
''')
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(['*2 passed in*'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue