File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 11"""Fixtures for tests."""
22
3+ import random
34import sys
45from pathlib import Path
56
7+ import numpy as np
68import pytest
9+ import torch
710
811from 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 )
You can’t perform that action at this time.
0 commit comments