|
| 1 | +import textwrap |
| 2 | + |
1 | 3 | import pytest |
2 | 4 | import json |
3 | 5 | import commands |
4 | 6 | import pathlib |
5 | 7 | import tomllib |
6 | 8 |
|
| 9 | +# Last known Rust version that doesn't cause integration test failures. |
| 10 | +# TODO: remove this pinning once we figure out what's going wrong with newer versions. |
| 11 | +_PINNED_TOOLCHAIN = "1.94.1" |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture(autouse=True) |
| 15 | +def _pin_rust_toolchain(cwd): |
| 16 | + """Pin the Rust toolchain for integration tests. |
| 17 | +
|
| 18 | + Integration tests run from temporary directories, so they don't pick up |
| 19 | + rust-toolchain.toml via rustup's file-based resolution. Writing the file |
| 20 | + into the test's working directory ensures a consistent toolchain version |
| 21 | + regardless of what is pre-installed on the runner image. |
| 22 | +
|
| 23 | + The toolchain must be pre-installed by the CI prepare action to avoid |
| 24 | + concurrent rustup installs from parallel pytest-xdist workers. |
| 25 | + """ |
| 26 | + (cwd / "rust-toolchain.toml").write_text(textwrap.dedent(f"""\ |
| 27 | + [toolchain] |
| 28 | + channel = "{_PINNED_TOOLCHAIN}" |
| 29 | + components = ["rust-src"] |
| 30 | + """)) |
| 31 | + |
7 | 32 |
|
8 | 33 | @pytest.fixture(params=[2018, 2021, 2024]) |
9 | 34 | def rust_edition(request): |
@@ -33,7 +58,7 @@ def update(file): |
33 | 58 |
|
34 | 59 | @pytest.fixture(scope="session") |
35 | 60 | def rust_sysroot_src() -> str: |
36 | | - rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True)) |
| 61 | + rust_sysroot = pathlib.Path(commands.run(f"rustc +{_PINNED_TOOLCHAIN} --print sysroot", _capture=True)) |
37 | 62 | ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library") |
38 | 63 | assert ret.exists() |
39 | 64 | return str(ret) |
|
0 commit comments