From b39f957b88b6f44252c0ad2eb289b92fd7937f8e Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Wed, 26 Jul 2017 10:08:54 +0100 Subject: Add test of issue #920 --- testing/python/fixture.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'testing') diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 8dd713416..1801c91ff 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -2547,6 +2547,40 @@ class TestFixtureMarker(object): '*test_foo*alpha*', '*test_foo*beta*']) + @pytest.mark.issue920 + @pytest.mark.xfail(reason="Fixture reordering not deterministic with hash randomisation") + 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"), [ -- cgit v1.2.3 From a546a612bde02292488b6f9b3185a950d61fbe94 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Tue, 25 Jul 2017 19:54:27 +0100 Subject: Fix nondeterminism in fixture collection order fixtures.reorder_items is non-deterministic because it reorders based on iteration over an (unordered) set. Change the code to use an OrderedDict instead so that we get deterministic behaviour, fixes #920. --- testing/python/fixture.py | 1 - 1 file changed, 1 deletion(-) (limited to 'testing') diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 1801c91ff..f8aef802f 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -2548,7 +2548,6 @@ class TestFixtureMarker(object): '*test_foo*beta*']) @pytest.mark.issue920 - @pytest.mark.xfail(reason="Fixture reordering not deterministic with hash randomisation") def test_deterministic_fixture_collection(self, testdir, monkeypatch): testdir.makepyfile(""" import pytest -- cgit v1.2.3