From 31082d9228558dd73fac8c23a373b9b0089feb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Thu, 13 Aug 2026 10:00:59 +0200 Subject: [PATCH 1/2] Run repository-creating tests in temp dirs --- tests/test_batch_runner.py | 5 +++++ tests/test_cli.py | 5 +++++ tests/test_git_adapter.py | 5 +++++ tests/test_gitlab_api.py | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/tests/test_batch_runner.py b/tests/test_batch_runner.py index e01a90c..cb3ae2b 100644 --- a/tests/test_batch_runner.py +++ b/tests/test_batch_runner.py @@ -7,6 +7,11 @@ from cadetrdm.io_utils import delete_path +@pytest.fixture(autouse=True) +def isolated_cwd(tmp_path, monkeypatch): + monkeypatch.chdir(tmp_path) + + @pytest.mark.server_api def test_module_import(): WORK_DIR = Path.cwd() / "tmp" diff --git a/tests/test_cli.py b/tests/test_cli.py index ce0abe3..995ab6e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -11,6 +11,11 @@ runner = CliRunner() +@pytest.fixture(autouse=True) +def isolated_cwd(tmp_path, monkeypatch): + monkeypatch.chdir(tmp_path) + + def create_repo(): if os.path.exists("test_repo_cli"): delete_path("test_repo_cli") diff --git a/tests/test_git_adapter.py b/tests/test_git_adapter.py index 9984338..9dcb498 100644 --- a/tests/test_git_adapter.py +++ b/tests/test_git_adapter.py @@ -14,6 +14,11 @@ from cadetrdm.wrapper import tracks_results +@pytest.fixture(autouse=True) +def isolated_cwd(tmp_path, monkeypatch): + monkeypatch.chdir(tmp_path) + + @pytest.fixture(scope="module") def path_to_repo(): # a "fixture" serves up shared, ready variables to test functions that should use the fixture as a kwarg diff --git a/tests/test_gitlab_api.py b/tests/test_gitlab_api.py index 4ee1fc8..3adf06d 100644 --- a/tests/test_gitlab_api.py +++ b/tests/test_gitlab_api.py @@ -9,6 +9,11 @@ from cadetrdm.repositories import BaseRepo +@pytest.fixture(autouse=True) +def isolated_cwd(tmp_path, monkeypatch): + monkeypatch.chdir(tmp_path) + + @pytest.mark.server_api def test_gitlab_create(): url = "https://jugit.fz-juelich.de/" From 69593faceb287d86e26d3bac98fbbbdd500efae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schm=C3=B6lder?= Date: Thu, 13 Aug 2026 10:15:52 +0200 Subject: [PATCH 2/2] Make git adapter code changes deterministic --- tests/test_git_adapter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_git_adapter.py b/tests/test_git_adapter.py index 9dcb498..1c27678 100644 --- a/tests/test_git_adapter.py +++ b/tests/test_git_adapter.py @@ -1,5 +1,5 @@ import os -import random +import uuid from pathlib import Path import git @@ -27,7 +27,7 @@ def path_to_repo(): def modify_code(path_to_repo): # Add changes to the project code - random_number = random.randint(0, 265) + random_number = uuid.uuid4().int filepath = path_to_repo / f"print_random_number.py" with open(filepath, "w") as file: file.write(f"print({random_number})\n")