Skip to content

Make slow pytest tests opt-in by default#1345

Open
marko1olo wants to merge 1 commit into
quantumlib:mainfrom
marko1olo:fix-default-skip-slow-tests
Open

Make slow pytest tests opt-in by default#1345
marko1olo wants to merge 1 commit into
quantumlib:mainfrom
marko1olo:fix-default-skip-slow-tests

Conversation

@marko1olo

@marko1olo marko1olo commented Jun 7, 2026

Copy link
Copy Markdown

Fixes #1327.

This makes tests marked slow opt-in by default for normal pytest runs, while preserving explicit ways to include them:

  • --run-slow includes slow tests.
  • -m slow and other explicit marker expressions mentioning slow are left to pytest.
  • Regular CI jobs can stop spelling -m "not slow"; nightly pytest and incremental coverage still pass --run-slow.

The new option lives in the repository-level conftest.py, so pytest knows about it before collection and before wrapper scripts pass --run-slow.

Local validation:

  • python -m pytest src/openfermion/testing/pytest_config_test.py -q -> 4 passed
  • python -m pytest src/openfermion/ops/representations/doci_hamiltonian_test.py -q -> 12 passed, 1 deselected
  • python -m pytest src/openfermion/ops/representations/doci_hamiltonian_test.py -q --run-slow -> 13 passed
  • python -m black --check conftest.py src/openfermion/testing/pytest_config_test.py
  • python -m pylint conftest.py src/openfermion/testing/pytest_config_test.py
  • parsed .github/workflows/ci.yaml and .github/workflows/nightly-pytest.yaml with PyYAML
  • git diff --check origin/main..HEAD

@google-cla

google-cla Bot commented Jun 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request configures pytest to skip tests marked as 'slow' by default, introducing a new --run-slow command-line option to include them. It updates the documentation, helper scripts, and configuration files accordingly, and adds unit tests to verify the behavior. One issue was identified in conftest.py where a potential TypeError could occur if the -m option returns None, and a code suggestion was provided to handle this safely.

Comment thread conftest.py
Comment on lines +26 to +27
markexpr = config.getoption("-m", default="")
if config.getoption("--run-slow") or _SLOW_MARKER_RE.search(markexpr):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

If config.getoption("-m") returns None (which can happen in certain environments or when pytest is run programmatically), calling _SLOW_MARKER_RE.search(markexpr) will raise a TypeError: expected string or bytes-like object. We should ensure markexpr is a truthy string before performing the regex search.

Suggested change
markexpr = config.getoption("-m", default="")
if config.getoption("--run-slow") or _SLOW_MARKER_RE.search(markexpr):
markexpr = config.getoption("-m", default="")
if config.getoption("--run-slow") or (markexpr and _SLOW_MARKER_RE.search(markexpr)):

@marko1olo marko1olo force-pushed the fix-default-skip-slow-tests branch from ba85175 to bb99609 Compare June 7, 2026 02:58
Skip tests marked slow by default. Add --run-slow and keep explicit slow marker expressions working, while nightly and coverage checks still include slow tests.
@marko1olo marko1olo force-pushed the fix-default-skip-slow-tests branch from bb99609 to f085dac Compare June 7, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make -m "not slow" be default for pytest

1 participant