Skip to content

Commit

Permalink
ci: add update-ui-tests nox session (PyO3#3979)
Browse files Browse the repository at this point in the history
* ci: add `update-ui-tests` nox session

* defer error messages after the group closes

* fix syntax warnings
  • Loading branch information
davidhewitt authored Mar 22, 2024
1 parent 20e477a commit 9808f71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
15 changes: 11 additions & 4 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ Tests run with all supported Python versions with the latest stable Rust compile
If you are adding a new feature, you should add it to the `full` feature in our *Cargo.toml** so that it is tested in CI.

You can run these tests yourself with
```nox```
and
```nox -l```
lists further commands you can run.
`nox`. Use `nox -l` to list the full set of subcommands you can run.

#### UI Tests

PyO3 uses [`trybuild`][trybuild] to develop UI tests to capture error messages from the Rust compiler for some of the macro functionality.

Because there are several feature combinations for these UI tests, when updating them all (e.g. for a new Rust compiler version) it may be helpful to use the `update-ui-tests` nox session:

```bash
nox -s update-ui-tests
```

### Documenting changes

Expand Down
31 changes: 26 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ def check_guide(session: nox.Session):
session.posargs.extend(posargs)

remaps = {
f"file://{PYO3_GUIDE_SRC}/([^/]*/)*?%7B%7B#PYO3_DOCS_URL\}}\}}": f"file://{PYO3_DOCS_TARGET}",
"%7B%7B#PYO3_DOCS_VERSION\}\}": "latest",
f"file://{PYO3_GUIDE_SRC}/([^/]*/)*?%7B%7B#PYO3_DOCS_URL}}}}": f"file://{PYO3_DOCS_TARGET}",
"%7B%7B#PYO3_DOCS_VERSION}}": "latest",
}
remap_args = []
for key, value in remaps.items():
Expand Down Expand Up @@ -732,6 +732,16 @@ def check_feature_powerset(session: nox.Session):
)


@nox.session(name="update-ui-tests", venv_backend="none")
def update_ui_tests(session: nox.Session):
env = os.environ.copy()
env["TRYBUILD"] = "overwrite"
command = ["test", "--test", "test_compile_error"]
_run_cargo(session, *command, env=env)
_run_cargo(session, *command, "--features=full", env=env)
_run_cargo(session, *command, "--features=abi3,full", env=env)


def _build_docs_for_ffi_check(session: nox.Session) -> None:
# pyo3-ffi-check needs to scrape docs of pyo3-ffi
_run_cargo(session, "doc", _FFI_CHECK, "-p", "pyo3-ffi", "--no-deps")
Expand Down Expand Up @@ -813,12 +823,23 @@ def _get_coverage_env() -> Dict[str, str]:
def _run(session: nox.Session, *args: str, **kwargs: Any) -> None:
"""Wrapper for _run(session, which creates nice groups on GitHub Actions."""
is_github_actions = _is_github_actions()
failed = False
if is_github_actions:
# Insert ::group:: at the start of nox's command line output
print("::group::", end="", flush=True, file=sys.stderr)
session.run(*args, **kwargs)
if is_github_actions:
print("::endgroup::", file=sys.stderr)
try:
session.run(*args, **kwargs)
except nox.command.CommandFailed:
failed = True
raise
finally:
if is_github_actions:
print("::endgroup::", file=sys.stderr)
# Defer the error message until after the group to make them easier
# to find in the log
if failed:
command = " ".join(args)
print(f"::error::`{command}` failed", file=sys.stderr)


def _run_cargo(
Expand Down

0 comments on commit 9808f71

Please sign in to comment.