Skip to content

Commit 10f68cc

Browse files
tomcodgenrushilpatel0jemeza-codegenjayhackcodegen-bot
authored
CG-10450 Integration tests improvements (#145)
# Motivation We want to allow running integration tests for unauthenticated contributors. # Content - removed installing ghcli from the code - make sure REPO_ID_TO_URL is populated properly - don't prompt user for auth if not using lfs # Testing Manual testing. # Please check the following before marking your PR as ready for review - [x] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed - [x] I have read and agree to the [Contributor License Agreement](../CLA.md) --------- Co-authored-by: Rushil Patel <[email protected]> Co-authored-by: jemeza-codegen <[email protected]> Co-authored-by: Jay Hack <[email protected]> Co-authored-by: codegen-bot <[email protected]> Co-authored-by: Carol Jung <[email protected]> Co-authored-by: Edward-Codegen <[email protected]> Co-authored-by: eacodegen <[email protected]> Co-authored-by: Tawsif Kamal <[email protected]> Co-authored-by: Codegen Team (Internal) <[email protected]> Co-authored-by: bagel897 <[email protected]> Co-authored-by: Joel Aguero <[email protected]> Co-authored-by: Christine Wang <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Edo Pujol <[email protected]> Co-authored-by: KopekC <[email protected]>
1 parent 5c32360 commit 10f68cc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/conftest.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import logging
22
import os
3+
from pathlib import Path
4+
5+
import pytest
36

47
from tests.shared.codemod.models import Size
58

@@ -74,3 +77,45 @@ def pytest_configure(config):
7477
filename=f"build/logs/tests_{worker_id}.log",
7578
level=config.getini("log_file_level"),
7679
)
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

Comments
 (0)