Skip to content

Commit b39f957

Browse files
committed
Add test of issue #920
1 parent 309152d commit b39f957

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

testing/python/fixture.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,40 @@ def test_foo(fix):
25472547
'*test_foo*alpha*',
25482548
'*test_foo*beta*'])
25492549

2550+
@pytest.mark.issue920
2551+
@pytest.mark.xfail(reason="Fixture reordering not deterministic with hash randomisation")
2552+
def test_deterministic_fixture_collection(self, testdir, monkeypatch):
2553+
testdir.makepyfile("""
2554+
import pytest
2555+
2556+
@pytest.fixture(scope="module",
2557+
params=["A",
2558+
"B",
2559+
"C"])
2560+
def A(request):
2561+
return request.param
2562+
2563+
@pytest.fixture(scope="module",
2564+
params=["DDDDDDDDD", "EEEEEEEEEEEE", "FFFFFFFFFFF", "banansda"])
2565+
def B(request, A):
2566+
return request.param
2567+
2568+
def test_foo(B):
2569+
# Something funky is going on here.
2570+
# Despite specified seeds, on what is collected,
2571+
# sometimes we get unexpected passes. hashing B seems
2572+
# to help?
2573+
assert hash(B) or True
2574+
""")
2575+
monkeypatch.setenv("PYTHONHASHSEED", "1")
2576+
out1 = testdir.runpytest_subprocess("-v")
2577+
monkeypatch.setenv("PYTHONHASHSEED", "2")
2578+
out2 = testdir.runpytest_subprocess("-v")
2579+
out1 = [line for line in out1.outlines if line.startswith("test_deterministic_fixture_collection.py::test_foo")]
2580+
out2 = [line for line in out2.outlines if line.startswith("test_deterministic_fixture_collection.py::test_foo")]
2581+
assert len(out1) == 12
2582+
assert out1 == out2
2583+
25502584

25512585
class TestRequestScopeAccess(object):
25522586
pytestmark = pytest.mark.parametrize(("scope", "ok", "error"), [

0 commit comments

Comments
 (0)