Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: only skip validation tests when given explicit flag #472

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session scope is not strictly necessary, but seems a good thing to have

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
Loading