Skip to content

Commit 4490142

Browse files
author
tkucar
committed
add nicer pytest skip message
1 parent 22b095b commit 4490142

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/codegen/sdk/testing/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Repo(BaseModel):
6060
def from_json(cls, json_str: str) -> "Repo":
6161
return cls.model_validate(json.loads(json_str))
6262

63-
def to_op(self, name: str, token: str | None) -> LocalRepoOperator:
63+
def to_op(self, name: str, token: str | None) -> LocalRepoOperator | tuple[None, str | None]:
6464
base_path = BASE_TMP_DIR / ("extra_repos" if self.extra_repo else "oss_repos") / name
6565
base_path.mkdir(exist_ok=True, parents=True)
6666
url = self.url
@@ -71,11 +71,12 @@ def to_op(self, name: str, token: str | None) -> LocalRepoOperator:
7171
# if REPO_ID_TO_URL is not set, we probably don't need auth. this is assuming that for
7272
# OSS repos, we don't need to pull any private repos.
7373
if not REPO_ID_TO_URL:
74-
return
74+
return (None, "Could not create repo operator - skipping test")
7575

7676
if not which("gh"):
77-
raise RuntimeError("GitHub CLI (gh) is not installed. Please install it first.")
77+
return (None, "GitHub CLI (gh) is not installed. Please install it first. Skipping test.")
7878
if '[credential "https://github.codegen.app"]' not in (Path.home() / ".gitconfig").read_text():
79+
print("Setting up auth using the github cli")
7980
os.system("gh auth login -h github.codegen.app")
8081
os.system("gh auth setup-git -h github.codegen.app")
8182
return LocalRepoOperator.create_from_commit(str(base_path), self.default_branch, self.commit, url)

tests/codemod/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ def token(request):
141141
def op(repo: Repo, token: str | None) -> YieldFixture[LocalRepoOperator]:
142142
with filelock.FileLock(BASE_TMP_DIR / "locks" / repo.name):
143143
op = repo.to_op(repo.name, token)
144-
if op is None:
145-
pytest.skip("Could not create repo operator - skipping test")
144+
if isinstance(op, tuple):
145+
# This means we got (None, error_message)
146+
_, msg = op
147+
pytest.skip(msg or "Could not create repo operator")
146148
yield op
147149

148150

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)