@@ -78,7 +78,31 @@ 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 ("--randomly-dont-reorganize" , "--randomly-dont-seed-per-test" )
82
+ out .assert_outcomes (passed = 2 , failed = 0 )
83
+
84
+
85
+ def test_it_uses_different_random_seed_per_test (ourtester ):
86
+ """
87
+ Run a pair of tests that generate a number and assert they produce
88
+ different numbers.
89
+ """
90
+ ourtester .makepyfile (
91
+ test_one = """
92
+ import random
93
+
94
+ def test_a():
95
+ test_a.num = random.random()
96
+ if hasattr(test_b, 'num'):
97
+ assert test_a.num != test_b.num
98
+
99
+ def test_b():
100
+ test_b.num = random.random()
101
+ if hasattr(test_a, 'num'):
102
+ assert test_b.num != test_a.num
103
+ """
104
+ )
105
+ out = ourtester .runpytest ()
82
106
out .assert_outcomes (passed = 2 , failed = 0 )
83
107
84
108
@@ -601,7 +625,7 @@ def test_two(myfixture):
601
625
assert random.getstate() == state_at_seed_two
602
626
"""
603
627
)
604
- args = ["--randomly-seed=2" ]
628
+ args = ["--randomly-seed=2" , "--randomly-dont-seed-per-test" ]
605
629
606
630
out = ourtester .runpytest (* args )
607
631
out .assert_outcomes (passed = 2 )
@@ -633,7 +657,7 @@ def test_b():
633
657
"""
634
658
)
635
659
636
- out = ourtester .runpytest ("--randomly-seed=1" )
660
+ out = ourtester .runpytest ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
637
661
out .assert_outcomes (passed = 2 )
638
662
639
663
@@ -645,10 +669,10 @@ def test_faker(ourtester):
645
669
fake = Faker()
646
670
647
671
def test_one():
648
- assert fake.name() == 'Ryan Gallagher '
672
+ assert fake.name() == 'Justin Richard '
649
673
650
674
def test_two():
651
- assert fake.name() == 'Ryan Gallagher '
675
+ assert fake.name() == 'Tiffany Williams '
652
676
"""
653
677
)
654
678
@@ -692,7 +716,7 @@ def test_b():
692
716
"""
693
717
)
694
718
695
- out = ourtester .runpytest ("--randomly-seed=1" )
719
+ out = ourtester .runpytest ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
696
720
out .assert_outcomes (passed = 2 )
697
721
698
722
@@ -702,10 +726,10 @@ def test_numpy(ourtester):
702
726
import numpy as np
703
727
704
728
def test_one():
705
- assert np.random.rand() == 0.417022004702574
729
+ assert np.random.rand() == 0.46479378116435255
706
730
707
731
def test_two():
708
- assert np.random.rand() == 0.417022004702574
732
+ assert np.random.rand() == 0.6413112443155088
709
733
"""
710
734
)
711
735
@@ -765,7 +789,7 @@ def fake_entry_points(*, group):
765
789
entry_points .append (_FakeEntryPoint ("test_seeder" , reseed ))
766
790
767
791
# Need to run in-process so that monkeypatching works
768
- pytester .runpytest_inprocess ("--randomly-seed=1" )
792
+ pytester .runpytest_inprocess ("--randomly-seed=1" , "--randomly-dont-seed-per-test" )
769
793
assert reseed .mock_calls == [
770
794
mock .call (1 ),
771
795
mock .call (1 ),
@@ -775,7 +799,7 @@ def fake_entry_points(*, group):
775
799
]
776
800
777
801
reseed .mock_calls [:] = []
778
- pytester .runpytest_inprocess ("--randomly-seed=424242" )
802
+ pytester .runpytest_inprocess ("--randomly-seed=424242" , "--randomly-dont-seed-per-test" )
779
803
assert reseed .mock_calls == [
780
804
mock .call (424242 ),
781
805
mock .call (424242 ),
0 commit comments