@@ -78,7 +78,33 @@ def test_b():
78
78
assert test_b.num == test_a.num
79
79
"""
80
80
)
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 ()
82
108
out .assert_outcomes (passed = 2 , failed = 0 )
83
109
84
110
@@ -601,7 +627,7 @@ def test_two(myfixture):
601
627
assert random.getstate() == state_at_seed_two
602
628
"""
603
629
)
604
- args = ["--randomly-seed=2" ]
630
+ args = ["--randomly-seed=2" , "--randomly-dont-seed-per-test" ]
605
631
606
632
out = ourtester .runpytest (* args )
607
633
out .assert_outcomes (passed = 2 )
@@ -633,7 +659,7 @@ def test_b():
633
659
"""
634
660
)
635
661
636
- out = ourtester .runpytest ("--randomly-seed=1" )
662
+ out = ourtester .runpytest ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
637
663
out .assert_outcomes (passed = 2 )
638
664
639
665
@@ -645,10 +671,10 @@ def test_faker(ourtester):
645
671
fake = Faker()
646
672
647
673
def test_one():
648
- assert fake.name() == 'Ryan Gallagher '
674
+ assert fake.name() == 'Justin Richard '
649
675
650
676
def test_two():
651
- assert fake.name() == 'Ryan Gallagher '
677
+ assert fake.name() == 'Tiffany Williams '
652
678
"""
653
679
)
654
680
@@ -692,7 +718,7 @@ def test_b():
692
718
"""
693
719
)
694
720
695
- out = ourtester .runpytest ("--randomly-seed=1" )
721
+ out = ourtester .runpytest ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
696
722
out .assert_outcomes (passed = 2 )
697
723
698
724
@@ -702,10 +728,10 @@ def test_numpy(ourtester):
702
728
import numpy as np
703
729
704
730
def test_one():
705
- assert np.random.rand() == 0.417022004702574
731
+ assert np.random.rand() == 0.46479378116435255
706
732
707
733
def test_two():
708
- assert np.random.rand() == 0.417022004702574
734
+ assert np.random.rand() == 0.6413112443155088
709
735
"""
710
736
)
711
737
@@ -765,7 +791,7 @@ def fake_entry_points(*, group):
765
791
entry_points .append (_FakeEntryPoint ("test_seeder" , reseed ))
766
792
767
793
# 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" )
769
795
assert reseed .mock_calls == [
770
796
mock .call (1 ),
771
797
mock .call (1 ),
@@ -775,7 +801,9 @@ def fake_entry_points(*, group):
775
801
]
776
802
777
803
reseed .mock_calls [:] = []
778
- pytester .runpytest_inprocess ("--randomly-seed=424242" )
804
+ pytester .runpytest_inprocess (
805
+ "--randomly-seed=424242" , "--randomly-dont-seed-per-test"
806
+ )
779
807
assert reseed .mock_calls == [
780
808
mock .call (424242 ),
781
809
mock .call (424242 ),
0 commit comments