diff --git a/tests/unit_tests/hyperion/conftest.py b/tests/unit_tests/hyperion/conftest.py index 9e012c754..e4cc37ba7 100644 --- a/tests/unit_tests/hyperion/conftest.py +++ b/tests/unit_tests/hyperion/conftest.py @@ -1,3 +1,4 @@ +from importlib import resources from pathlib import Path from unittest.mock import patch @@ -9,12 +10,17 @@ @pytest.fixture(autouse=True) def patch_open_to_prevent_dls_reads_in_tests(): unpatched_open = open + project_folder = resources.files(__package__) + assert isinstance(project_folder, Path) + project_folder = project_folder.parent.parent.parent def patched_open(*args, **kwargs): requested_path = Path(args[0]) if requested_path.is_absolute(): for p in BANNED_PATHS: - assert not requested_path.is_relative_to(p), ( + assert not requested_path.is_relative_to( + p + ) or requested_path.is_relative_to(project_folder), ( f"Attempt to open {requested_path} from inside a unit test" ) return unpatched_open(*args, **kwargs)