@@ -78,7 +78,33 @@ def test_b():
7878 assert test_b.num == test_a.num
7979 """
8080 )
81- out = ourtester .runpytest ("--randomly-dont-reorganize" )
81+ out = ourtester .runpytest (
82+ "--randomly-dont-reorganize" , "--randomly-dont-seed-per-test"
83+ )
84+ out .assert_outcomes (passed = 2 , failed = 0 )
85+
86+
87+ def test_it_uses_different_random_seed_per_test (ourtester ):
88+ """
89+ Run a pair of tests that generate a number and assert they produce
90+ different numbers.
91+ """
92+ ourtester .makepyfile (
93+ test_one = """
94+ import random
95+
96+ def test_a():
97+ test_a.num = random.random()
98+ if hasattr(test_b, 'num'):
99+ assert test_a.num != test_b.num
100+
101+ def test_b():
102+ test_b.num = random.random()
103+ if hasattr(test_a, 'num'):
104+ assert test_b.num != test_a.num
105+ """
106+ )
107+ out = ourtester .runpytest ()
82108 out .assert_outcomes (passed = 2 , failed = 0 )
83109
84110
@@ -601,7 +627,7 @@ def test_two(myfixture):
601627 assert random.getstate() == state_at_seed_two
602628 """
603629 )
604- args = ["--randomly-seed=2" ]
630+ args = ["--randomly-seed=2" , "--randomly-dont-seed-per-test" ]
605631
606632 out = ourtester .runpytest (* args )
607633 out .assert_outcomes (passed = 2 )
@@ -633,7 +659,7 @@ def test_b():
633659 """
634660 )
635661
636- out = ourtester .runpytest ("--randomly-seed=1" )
662+ out = ourtester .runpytest ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
637663 out .assert_outcomes (passed = 2 )
638664
639665
@@ -645,10 +671,10 @@ def test_faker(ourtester):
645671 fake = Faker()
646672
647673 def test_one():
648- assert fake.name() == 'Ryan Gallagher '
674+ assert fake.name() == 'Justin Richard '
649675
650676 def test_two():
651- assert fake.name() == 'Ryan Gallagher '
677+ assert fake.name() == 'Tiffany Williams '
652678 """
653679 )
654680
@@ -692,7 +718,7 @@ def test_b():
692718 """
693719 )
694720
695- out = ourtester .runpytest ("--randomly-seed=1" )
721+ out = ourtester .runpytest ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
696722 out .assert_outcomes (passed = 2 )
697723
698724
@@ -702,10 +728,10 @@ def test_numpy(ourtester):
702728 import numpy as np
703729
704730 def test_one():
705- assert np.random.rand() == 0.417022004702574
731+ assert np.random.rand() == 0.46479378116435255
706732
707733 def test_two():
708- assert np.random.rand() == 0.417022004702574
734+ assert np.random.rand() == 0.6413112443155088
709735 """
710736 )
711737
@@ -765,7 +791,7 @@ def fake_entry_points(*, group):
765791 entry_points .append (_FakeEntryPoint ("test_seeder" , reseed ))
766792
767793 # Need to run in-process so that monkeypatching works
768- pytester .runpytest_inprocess ("--randomly-seed=1" )
794+ pytester .runpytest_inprocess ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
769795 assert reseed .mock_calls == [
770796 mock .call (1 ),
771797 mock .call (1 ),
@@ -775,7 +801,9 @@ def fake_entry_points(*, group):
775801 ]
776802
777803 reseed .mock_calls [:] = []
778- pytester .runpytest_inprocess ("--randomly-seed=424242" )
804+ pytester .runpytest_inprocess (
805+ "--randomly-seed=424242" , "--randomly-dont-seed-per-test"
806+ )
779807 assert reseed .mock_calls == [
780808 mock .call (424242 ),
781809 mock .call (424242 ),
0 commit comments