Skip to content

Commit

Permalink
test: only skip validation tests when given explicit flag (#472)
Browse files Browse the repository at this point in the history
pytest previously skipped the validation tests if the validator was not
built, leading to the situation in #468 where many tests were
accidentally skipped in CI.

Instead, fail the tests if the validator is not installed, but allow
`pytest --no_validation` to skip them instead.

The possibility of doing similar for execution tests (somewhat-silently
skipped if `execute-llvm` isn't installed) is left for a later PR.

---------

Co-authored-by: Kartik Singhal <[email protected]>
  • Loading branch information
acl-cqc and qartik authored Sep 16, 2024
1 parent 0b156e9 commit d9ba592
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ uv run pre-commit install
Run tests using

```sh
uv run pytest -v
uv run pytest [-v] # -v just enables verbose test output
```

(If you have not built the validator, you can do `uv run pytest --no_validation`.)

You have to install extra dependencies to test automatic circuit conversion from `pytket`.

```sh
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ def dir_path(s):
type=dir_path,
help="A directory to which to export test cases",
)

parser.addoption(
"--no_validation",
dest="validation",
action="store_false",
help="Disable validation tests (run by default)",
)
13 changes: 7 additions & 6 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess


@pytest.fixture
@pytest.fixture(scope="session")
def export_test_cases_dir(request):
r = request.config.getoption("--export-test-cases")
if r and not r.exists():
Expand All @@ -26,16 +26,17 @@ def get_validator() -> Path | None:
return None


@pytest.fixture
@pytest.fixture(scope="session")
def validate(request, export_test_cases_dir: Path):
def validate_json(hugr: str):
if request.config.getoption("validation"):
# Check if the validator is installed
validator = get_validator()
if validator is None:
pytest.skip(
"Skipping validation: Run `cargo build` to install the validator"
)
pytest.fail("Run `cargo build -p release` to install the validator")
else:
pytest.skip("Skipping validation tests as requested")

def validate_json(hugr: str):
# Executes `cargo run -p validator -- validate -`
# passing the hugr JSON as stdin
p = subprocess.run( # noqa: S603
Expand Down

0 comments on commit d9ba592

Please sign in to comment.