Skip to content

Commit 286e5e7

Browse files
committed
feat(test-cli): append pytest command to Github Actions job summary
When `$GITHUB_STEP_SUMMARY` is set, `PytestRunner` now also appends the resolved `pytest ...` invocation to the step summary as a fenced code block, so it can be copied from the Actions "Summary" panel of a failing run instead of scrolling through the log. Outside Github Actions the env var is unset and behavior is unchanged.
1 parent 4600089 commit 286e5e7

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

docs/dev/test_actions_locally.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,4 @@ The pytest-based CLIs (`fill`, `execute`, ...) print the resolved `pytest ...` i
120120
Executing: pytest ...
121121
```
122122
123-
Copy this line verbatim from the failing Github Actions log and run it locally to reproduce the exact command, including all plugin and marker arguments injected by the CLI.
123+
When run under Github Actions, the same command is also appended to the job summary (via `$GITHUB_STEP_SUMMARY`), so it can be copied directly from the "Summary" panel of the failing run without scrolling through the log.

packages/testing/src/execution_testing/cli/pytest_commands/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def run_single(self, execution: PytestExecution) -> int:
8888
if self._is_verbose(execution.args) or "CI" in os.environ:
8989
pytest_cmd = f"pytest {' '.join(pytest_args)}"
9090
self.error_console.print(f"Executing: [bold]{pytest_cmd}[/bold]")
91+
summary_path = os.environ.get("GITHUB_STEP_SUMMARY")
92+
if summary_path:
93+
with Path(summary_path).open("a") as summary:
94+
summary.write(
95+
f"### Executing\n\n```bash\n{pytest_cmd}\n```\n\n"
96+
)
9197

9298
return pytest.main(pytest_args)
9399

0 commit comments

Comments
 (0)