Skip to content

Fix hatch test crashing or silently doing nothing when filters match no environments - #2460

Open
taekop wants to merge 1 commit into
pypa:masterfrom
taekop:fix-test-no-matching-env
Open

taekop wants to merge 1 commit into
pypa:masterfrom
taekop:fix-test-no-matching-env

Conversation

@taekop

@taekop taekop commented Oct 6, 2026

Copy link
Copy Markdown

Fixes #1866

hatch test -i/-x with filters that match no environment left selected_envs empty. With --cover this hit selected_envs[0] and raised IndexError (the traceback in the issue). Without --cover it silently ran nothing and exited 0. hatch test now aborts with No environments were selected (same wording as hatch env run) and exit code 1. Added a bullet under Unreleased/Fixed in docs/history/hatch.md.

Verified on macOS: the four new cases in tests/cli/test/test_test.py (-i py=3.13, -x py=3.12,3.10,3.8, each with and without --cover) fail on unmodified master (IndexError, or exit 0) and pass with the change.

Ran pytest tests/cli/test tests/cli/env tests/utils (212 passed, 1 failed: tests/cli/env/test_create.py::test_new_selected_python, which fails identically on unmodified master in my environment), ruff check, ruff format --check, mypy src/hatch/cli/test.

I used Claude Code to write this change and the PR text, and reviewed and tested it myself.

This branch has not been deployed

No deployments
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.

hatch test fails with IndexError when getting unknown environment

1 participant