|
1 | 1 | import logging
|
2 | 2 | import os
|
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
3 | 6 |
|
4 | 7 | from tests.shared.codemod.models import Size
|
5 | 8 |
|
@@ -74,3 +77,45 @@ def pytest_configure(config):
|
74 | 77 | filename=f"build/logs/tests_{worker_id}.log",
|
75 | 78 | level=config.getini("log_file_level"),
|
76 | 79 | )
|
| 80 | + |
| 81 | + |
| 82 | +def is_git_lfs_pointer(file_path: Path) -> bool: |
| 83 | + """Check if a file is a git LFS pointer file""" |
| 84 | + try: |
| 85 | + with open(file_path) as f: |
| 86 | + first_line = f.readline().strip() |
| 87 | + return first_line == "version https://git-lfs.github.com/spec/v1" |
| 88 | + except Exception: |
| 89 | + return False |
| 90 | + |
| 91 | + |
| 92 | +@pytest.hookimpl(hookwrapper=True) |
| 93 | +def pytest_runtest_makereport(item, call): |
| 94 | + outcome = yield |
| 95 | + report = outcome.get_result() |
| 96 | + |
| 97 | + if report.when == "call" and report.failed: |
| 98 | + if "NodeJS or npm is not installed" in str(report.longrepr): |
| 99 | + raise RuntimeError("This test requires NodeJS and npm to be installed. Please install them before running the tests.") |
| 100 | + |
| 101 | + |
| 102 | +@pytest.fixture(autouse=True) |
| 103 | +def skip_lfs_tests(request): |
| 104 | + """Skip tests that depend on git LFS files if they haven't been pulled""" |
| 105 | + # Lets not run if we are in CI |
| 106 | + if os.getenv("CI") == "true" or os.getenv("CIRCLECI") == "true": |
| 107 | + return |
| 108 | + |
| 109 | + # Get the test module path |
| 110 | + test_path = Path(request.module.__file__) |
| 111 | + |
| 112 | + # Only run for integration tests |
| 113 | + if not str(test_path).startswith(str(Path.cwd() / "tests" / "integration")): |
| 114 | + return |
| 115 | + |
| 116 | + try: |
| 117 | + expected = request.getfixturevalue("expected") |
| 118 | + if isinstance(expected, Path) and is_git_lfs_pointer(expected): |
| 119 | + pytest.skip(f"Test requires git LFS file {expected} which hasn't been pulled") |
| 120 | + except Exception: |
| 121 | + pass |
0 commit comments