Skip to content

Commit 110f59a

Browse files
authored
[Bugfix] fix flaky test (#13089)
Signed-off-by: மனோஜ்குமார் பழனிச்சாமி <smartmanoj42857@gmail.com>
1 parent 2e3b969 commit 110f59a

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

tests/test_seed_behavior.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,17 @@
88

99

1010
def test_seed_behavior():
11-
# Test with seed=None
12-
Platform.seed_everything(None)
11+
# Test with a specific seed
12+
Platform.seed_everything(42)
1313
random_value_1 = random.randint(0, 100)
1414
np_random_value_1 = np.random.randint(0, 100)
1515
torch_random_value_1 = torch.randint(0, 100, (1, )).item()
1616

17-
Platform.seed_everything(None)
17+
Platform.seed_everything(42)
1818
random_value_2 = random.randint(0, 100)
1919
np_random_value_2 = np.random.randint(0, 100)
2020
torch_random_value_2 = torch.randint(0, 100, (1, )).item()
2121

22-
assert random_value_1 != random_value_2
23-
assert np_random_value_1 != np_random_value_2
24-
assert torch_random_value_1 != torch_random_value_2
25-
26-
# Test with a specific seed
27-
Platform.seed_everything(42)
28-
random_value_3 = random.randint(0, 100)
29-
np_random_value_3 = np.random.randint(0, 100)
30-
torch_random_value_3 = torch.randint(0, 100, (1, )).item()
31-
32-
Platform.seed_everything(42)
33-
random_value_4 = random.randint(0, 100)
34-
np_random_value_4 = np.random.randint(0, 100)
35-
torch_random_value_4 = torch.randint(0, 100, (1, )).item()
36-
37-
assert random_value_3 == random_value_4
38-
assert np_random_value_3 == np_random_value_4
39-
assert torch_random_value_3 == torch_random_value_4
22+
assert random_value_1 == random_value_2
23+
assert np_random_value_1 == np_random_value_2
24+
assert torch_random_value_1 == torch_random_value_2

0 commit comments

Comments
 (0)