Skip to content

Commit

Permalink
Fix unit test banned path check to allow access to project folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rtuck99 committed Jan 15, 2025
1 parent 967bc4e commit 4528e8a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/unit_tests/hyperion/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from importlib import resources
from pathlib import Path
from unittest.mock import patch

Expand All @@ -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)
Expand Down

0 comments on commit 4528e8a

Please sign in to comment.