summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2017-07-30 17:17:40 -0300
committerGitHub <noreply@github.com>2017-07-30 17:17:40 -0300
commit4cd87273791d1bfc1b39f1a181e623f80a7c1cfa (patch)
treedd39b044b34be57754e6d09c55164f4e030b49e9 /testing
parent768edde899fe3629a69d55289f82bb0d95635c06 (diff)
parentf047e078e2d1c8aba19015e151c1e78c5cbc1cff (diff)
downloadpytest-4cd87273791d1bfc1b39f1a181e623f80a7c1cfa.tar.gz
Merge pull request #2617 from wence-/fix/nondeterministic-fixtures
Fix nondeterminism in fixture collection order
Diffstat (limited to 'testing')
-rw-r--r--testing/python/fixture.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/testing/python/fixture.py b/testing/python/fixture.py
index 8dd713416..f8aef802f 100644
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -2547,6 +2547,39 @@ class TestFixtureMarker(object):
'*test_foo*alpha*',
'*test_foo*beta*'])
+ @pytest.mark.issue920
+ def test_deterministic_fixture_collection(self, testdir, monkeypatch):
+ testdir.makepyfile("""
+ import pytest
+
+ @pytest.fixture(scope="module",
+ params=["A",
+ "B",
+ "C"])
+ def A(request):
+ return request.param
+
+ @pytest.fixture(scope="module",
+ params=["DDDDDDDDD", "EEEEEEEEEEEE", "FFFFFFFFFFF", "banansda"])
+ def B(request, A):
+ return request.param
+
+ def test_foo(B):
+ # Something funky is going on here.
+ # Despite specified seeds, on what is collected,
+ # sometimes we get unexpected passes. hashing B seems
+ # to help?
+ assert hash(B) or True
+ """)
+ monkeypatch.setenv("PYTHONHASHSEED", "1")
+ out1 = testdir.runpytest_subprocess("-v")
+ monkeypatch.setenv("PYTHONHASHSEED", "2")
+ out2 = testdir.runpytest_subprocess("-v")
+ out1 = [line for line in out1.outlines if line.startswith("test_deterministic_fixture_collection.py::test_foo")]
+ out2 = [line for line in out2.outlines if line.startswith("test_deterministic_fixture_collection.py::test_foo")]
+ assert len(out1) == 12
+ assert out1 == out2
+
class TestRequestScopeAccess(object):
pytestmark = pytest.mark.parametrize(("scope", "ok", "error"), [