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:
Bruno Oliveira 2015-08-06 22:30:01 -03:00
parent 39f1471e93
commit 2bbe709bce
1 changed files with 13 additions and 4 deletions

View File

@ -168,8 +168,17 @@ class TestWarns(object):
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_double_test(self, testdir):
def test_doubletest(self, run):
"""If a test is run again, the warning should still be raised""" """If a test is run again, the warning should still be raised"""
with pytest.warns(RuntimeWarning): testdir.makepyfile('''
warnings.warn("runtime", RuntimeWarning) 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*'])