diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9c218399f..e642299f1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -130,7 +130,7 @@ jobs: - name: Run pytest run: | echo '::add-matcher::.github/problem-matchers/pytest.json' - check/pytest -n auto -m "not slow" + check/pytest -n auto --skipslow pytest-extra: name: Extra unit tests @@ -162,7 +162,7 @@ jobs: - name: Run pytest run: | echo '::add-matcher::.github/problem-matchers/pytest.json' - check/pytest -n auto -m "not slow" src/openfermion/resource_estimates + check/pytest -n auto --skipslow src/openfermion/resource_estimates pytest-compat: name: Python compatibility tests @@ -190,7 +190,7 @@ jobs: - name: Run pytest run: | echo '::add-matcher::.github/problem-matchers/pytest.json' - check/pytest -n auto -m "not slow" + check/pytest -n auto --skipslow coverage: name: Python code coverage tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e4b603e49..3db515805 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -293,7 +293,7 @@ We use [pytest](https://docs.pytest.org) to run our tests and in the `check/` subdirectory to run these programs. * During development, periodically check that code changes do not break anything. For fast checks, - run `check/pytest -m "not slow" -n auto PATH ...`, where `PATH ...` is one or more directories + run `check/pytest --skipslow -n auto PATH ...`, where `PATH ...` is one or more directories or `_test.py` files to test. (The `-n auto` option makes pytest use parallel processes; omit it if it causes problems on your system.) diff --git a/conftest.py b/conftest.py index 080bcba9d..3e50ce02f 100644 --- a/conftest.py +++ b/conftest.py @@ -66,3 +66,12 @@ def set_threadpool_limits(): yield else: yield + + +def pytest_addoption(parser: pytest.Parser) -> None: + parser.addoption("--skipslow", action="store_true", help="skips slow tests") + + +def pytest_runtest_setup(item: pytest.Item) -> None: + if "slow" in item.keywords and item.config.getoption("skipslow"): + pytest.skip("skipped because of --skipslow option") diff --git a/pyproject.toml b/pyproject.toml index 72ba61d15..b8aa9b48a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ disable_warnings = ["no-sysmon"] [tool.pytest.ini_options] markers = [ - """slow: marks tests as slow (deselect with '-m "not slow"')""", + """slow: marks tests as slow (skip with '--skipslow')""", ] filterwarnings = [ "ignore:Skipped assert_qasm_is_consistent_with_unitary because qiskit.*:UserWarning",