Skip to content

Commit b345eec

Browse files
Merge pull request #381 from omicsNLP/fix/fix-non-determinism-in-pdf-regression-test
fix: fix non-determinism in pdf regression test
2 parents 807dc63 + 635e730 commit b345eec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""Fixtures for tests."""
22

3+
import random
34
import sys
45
from pathlib import Path
56

7+
import numpy as np
68
import pytest
9+
import torch
710

811
from autocorpus.ac_bioc import (
912
BioCAnnotation,
@@ -130,3 +133,17 @@ def pytest_collection_modifyitems(config, items):
130133
item.add_marker(skip_ci_macos)
131134
if "skip_ci_windows" in item.keywords:
132135
item.add_marker(skip_ci_windows)
136+
137+
138+
def set_random_seeds(seed: int = 0) -> None:
139+
"""Fix random number generator seeds used by stochastic algorithms."""
140+
random.seed(seed)
141+
np.random.seed(seed)
142+
torch.manual_seed(seed)
143+
torch.cuda.manual_seed_all(seed)
144+
145+
146+
@pytest.fixture(scope="session", autouse=True)
147+
def deterministic_session():
148+
"""Session-scoped fixture to set random seeds for test reproducibility."""
149+
set_random_seeds(1234)

0 commit comments

Comments
 (0)