Skip to content

Commit 6eb0ab8

Browse files
committed
add test for cargo log output
1 parent 3931c55 commit 6eb0ab8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ jobs:
4848
with:
4949
python-version: "3.x"
5050

51+
- name: Install Rust toolchain
52+
uses: actions-rs/toolchain@v1
53+
with:
54+
toolchain: stable
55+
profile: minimal
56+
default: true
57+
5158
- run: pip install nox
5259

5360
- run: nox -s test

tests/test_extension.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
from pytest import CaptureFixture, MonkeyPatch
5+
6+
from setuptools_rust.extension import RustBin
7+
8+
9+
@pytest.fixture()
10+
def hello_world_bin() -> RustBin:
11+
setuptools_rust_dir = Path(__file__).parent.parent
12+
return RustBin(
13+
"hello-world",
14+
path=(
15+
setuptools_rust_dir / "examples" / "hello-world" / "Cargo.toml"
16+
).as_posix(),
17+
)
18+
19+
20+
def test_metadata_contents(hello_world_bin: RustBin) -> None:
21+
metadata = hello_world_bin._metadata(quiet=False)
22+
assert "target_directory" in metadata
23+
24+
25+
def test_metadata_cargo_log(
26+
capfd: CaptureFixture, monkeypatch: MonkeyPatch, hello_world_bin: RustBin
27+
) -> None:
28+
monkeypatch.setenv("CARGO_LOG", "trace")
29+
30+
# With quiet unset, no stdout, plenty of logging stderr
31+
hello_world_bin._metadata(quiet=False)
32+
captured = capfd.readouterr()
33+
assert captured.out == ""
34+
assert "TRACE cargo::util::config" in captured.err
35+
36+
# With quiet set, nothing will be printed
37+
hello_world_bin._metadata(quiet=True)
38+
captured = capfd.readouterr()
39+
assert captured.out == ""
40+
assert captured.err == ""

0 commit comments

Comments
 (0)