From da52bc0ecf03d188a6be6a9f8d12c898546d081b Mon Sep 17 00:00:00 2001 From: Benjamin Partridge Date: Mon, 12 Jan 2026 15:18:05 +0000 Subject: [PATCH 1/5] Added fixed random seed to pdf regression test --- tests/test_regression.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_regression.py b/tests/test_regression.py index b1c922f..28b60d7 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -141,6 +141,9 @@ def test_pdf_to_bioc(data_path: Path, input_file: str, config: dict[str, Any]) - ) as f: expected_tables = json.load(f) + import torch + torch.manual_seed(0) + auto_corpus = process_file(config=config, file_path=pdf_path) new_bioc = auto_corpus.main_text From 0118feaa4104f7f5dc2f20623d3a5fdfe8b1fb55 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 17:18:45 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_regression.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_regression.py b/tests/test_regression.py index 28b60d7..d28d2a6 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -142,8 +142,9 @@ def test_pdf_to_bioc(data_path: Path, input_file: str, config: dict[str, Any]) - expected_tables = json.load(f) import torch + torch.manual_seed(0) - + auto_corpus = process_file(config=config, file_path=pdf_path) new_bioc = auto_corpus.main_text From bf61e81852bbdec6e9276e768dfae4d4fd3ba3e8 Mon Sep 17 00:00:00 2001 From: Benjamin Partridge Date: Mon, 12 Jan 2026 17:40:07 +0000 Subject: [PATCH 3/5] Added seed fixing to conftest instead of pdf regression test itself --- tests/conftest.py | 15 +++++++++++++++ tests/test_regression.py | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 26b3568..7c2507d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,12 @@ """Fixtures for tests.""" +import random import sys from pathlib import Path +import numpy as np import pytest +import torch from autocorpus.ac_bioc import ( BioCAnnotation, @@ -130,3 +133,15 @@ def pytest_collection_modifyitems(config, items): item.add_marker(skip_ci_macos) if "skip_ci_windows" in item.keywords: item.add_marker(skip_ci_windows) + + +def set_random_seeds(seed: int = 0) -> None: + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + +@pytest.fixture(scope="session", autouse=True) +def deterministic_session(): + set_random_seeds(1234) + \ No newline at end of file diff --git a/tests/test_regression.py b/tests/test_regression.py index 28b60d7..1738b63 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -141,9 +141,7 @@ def test_pdf_to_bioc(data_path: Path, input_file: str, config: dict[str, Any]) - ) as f: expected_tables = json.load(f) - import torch - torch.manual_seed(0) - + auto_corpus = process_file(config=config, file_path=pdf_path) new_bioc = auto_corpus.main_text From 555f013cdf18629aad782c69becb15b3b4417289 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 17:45:31 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7c2507d..567ccb9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -141,7 +141,7 @@ def set_random_seeds(seed: int = 0) -> None: torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) + @pytest.fixture(scope="session", autouse=True) def deterministic_session(): set_random_seeds(1234) - \ No newline at end of file From 2aa0b95e301b77325df16c69d2fce79aacdf9930 Mon Sep 17 00:00:00 2001 From: Benjamin Partridge Date: Mon, 12 Jan 2026 18:02:45 +0000 Subject: [PATCH 5/5] Added docstrings to new conftest functions --- tests/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7c2507d..fcdc951 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -136,6 +136,7 @@ def pytest_collection_modifyitems(config, items): def set_random_seeds(seed: int = 0) -> None: + """Fix random number generator seeds used by stochastic algorithms.""" random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) @@ -143,5 +144,5 @@ def set_random_seeds(seed: int = 0) -> None: @pytest.fixture(scope="session", autouse=True) def deterministic_session(): + """Session-scoped fixture to set random seeds for test reproducibility.""" set_random_seeds(1234) - \ No newline at end of file