Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,36 @@

from dissect.target.plugin import OSPlugin

# Test if the data/ directory is present and if not, as is the case in Python
# source distributions of dissect.target, we give an error
data_dir = absolute_path("_data")
if not pathlib.Path(data_dir).is_dir():
raise pytest.PytestConfigWarning(
f"No test data directory {data_dir} found.\n"
"This can happen when you have downloaded the source distribution\n"
"of dissect.target from pypi.org. If so, retrieve the test data from\n"
"the dissect.target GitHub repository at:\n"
"https://github.com/fox-it/dissect.target"
)

def pytest_sessionstart(session: pytest.Session) -> None:
# Test if the _data/ directory is present and if not, as is the case in Python
# source distributions of dissect.target, we give an error
data_dir = absolute_path("_data")
if not data_dir.is_dir():
session.shouldfail = (
"! !\n"
f"No test data directory {data_dir} found.\n"
"This can happen when you have downloaded the source distribution\n"
"of dissect.target from pypi.org. If so, retrieve the test data from\n"
"the dissect.target GitHub repository at:\n"
"https://github.com/fox-it/dissect.target"
"\n! !"
)
else:
# Test if the test data looks like LFS references and if so, we give an error
# This can happen when git-lfs is not installed or not configured correctly
for file in (path for path in data_dir.rglob("*") if path.is_file()):
with file.open("rb") as fh:
if fh.read(42) == b"version https://git-lfs.github.com/spec/v1":
session.shouldfail = (
"! !\n"
"Test data files look like git-lfs references.\n"
"This can happen when git-lfs is not installed or not configured correctly.\n"
"Install git-lfs and run: \n"
"git lfs install && git lfs pull"
"\n! !"
)
break


@pytest.fixture(autouse=True)
Expand Down
Loading