From 2bbe709bcebc3d837a4e533cba63afe50d1fe2b0 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 6 Aug 2015 22:30:01 -0300 Subject: [PATCH] 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) --- testing/test_recwarn.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index b9707548d..644b09ef7 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -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""" - with pytest.warns(RuntimeWarning): - warnings.warn("runtime", RuntimeWarning) + 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*']) +