Skip to content

Commit 8617bf8

Browse files
authored
Merge pull request #435 from chrisburr/show-client-diff-on-failure
Show the diff if client regneration fails
2 parents 5008920 + ceca391 commit 8617bf8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

diracx-client/tests/test_regenerate.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ def test_regenerate_client(test_client, tmp_path):
7070
print("Running pre-commit...")
7171
subprocess.run(cmd, check=False, cwd=repo_root)
7272
print("Re-running pre-commit...")
73-
subprocess.run(cmd, check=True, cwd=repo_root)
74-
if repo.is_dirty(path=client_src):
75-
raise AssertionError("Client was regenerated with changes")
73+
proc = subprocess.run(cmd, check=False, cwd=repo_root)
74+
if proc.returncode == 0 and not repo.is_dirty(path=client_src):
75+
return
76+
# Show the diff to aid debugging
77+
print(repo.git.diff(client_src))
78+
if proc.returncode != 0:
79+
raise AssertionError("Pre-commit failed")
80+
raise AssertionError("Client was regenerated with changes")
7681

7782

7883
if __name__ == "__main__":

extensions/gubbins/gubbins-client/tests/test_regenerate.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,21 @@ def test_regenerate_client(test_client, tmp_path):
7575
# and use it
7676
# cmd += [f"--use=@autorest/python@{AUTOREST_VERSION}"]
7777

78-
subprocess.run(cmd, check=True) # noqa
78+
# ruff: noqa: S603
79+
subprocess.run(cmd, check=True)
7980

8081
cmd = ["pre-commit", "run", "--all-files"]
8182
print("Running pre-commit...")
82-
subprocess.run(cmd, check=False, cwd=repo_root) # noqa
83+
subprocess.run(cmd, check=False, cwd=repo_root)
8384
print("Re-running pre-commit...")
84-
subprocess.run(cmd, check=True, cwd=repo_root) # noqa
85-
if repo.is_dirty(path=client_src):
86-
raise AssertionError("Client was regenerated with changes")
85+
proc = subprocess.run(cmd, check=False, cwd=repo_root)
86+
if proc.returncode == 0 and not repo.is_dirty(path=client_src):
87+
return
88+
# Show the diff to aid debugging using gitpython
89+
print(repo.git.diff(client_src))
90+
if proc.returncode != 0:
91+
raise AssertionError("Pre-commit failed")
92+
raise AssertionError("Client was regenerated with changes")
8793

8894

8995
if __name__ == "__main__":

0 commit comments

Comments
 (0)