Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Fix syncing environment plugin requirements on standalone binaries built to forward to `pip`

- Fix the `test` command raising an `IndexError` with `--cover`, or silently doing nothing otherwise, when the `--include` or `--exclude` options match no environments. It now aborts with a clear message.

## [1.18.1](https://github.com/pypa/hatch/releases/tag/hatch-v1.18.1) - 2026-09-16 ## {: #hatch-v1.18.1 }

***Added:***
Expand Down
3 changes: 3 additions & 0 deletions src/hatch/cli/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def test(
else:
app.abort(f"No compatible environments found: {candidate_envs}")

if not selected_envs:
app.abort("No environments were selected")

test_script = "run-cov" if cover else "run"
patched_coverage = PatchedCoverageConfig(app.project.location, app.data_dir / ".config")
coverage_config_file = str(patched_coverage.internal_config_path)
Expand Down
51 changes: 51 additions & 0 deletions tests/cli/test/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,57 @@ def test_python(self, hatch, temp_dir, config_file, helpers, env_run, mocker):

assert not (data_path / ".config" / "coverage").exists()

@pytest.mark.parametrize(
"args",
[
pytest.param(("-i", "py=3.13"), id="include"),
pytest.param(("-i", "py=3.13", "--cover"), id="include-cover"),
pytest.param(("-x", "py=3.12,3.10,3.8"), id="exclude"),
pytest.param(("-x", "py=3.12,3.10,3.8", "--cover"), id="exclude-cover"),
],
)
def test_no_matching_environments(self, hatch, temp_dir, config_file, helpers, env_run, args):
config_file.model.template.plugins["default"]["tests"] = False
config_file.save()

project_name = "My.App"

with temp_dir.as_cwd():
result = hatch("new", project_name)

assert result.exit_code == 0, result.output

project_path = temp_dir / "my-app"
data_path = temp_dir / "data"
data_path.mkdir()

project = Project(project_path)
config = dict(project.raw_config)
config["tool"]["hatch"]["envs"] = {
"hatch-test": {
"matrix": [{"python": ["3.12", "3.10", "3.8"]}],
"scripts": {
"run": "test {env_name}",
"run-cov": "test with coverage",
"cov-combine": "combine coverage",
"cov-report": "show coverage",
},
}
}
project.save_config(config)

with project_path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}):
result = hatch("test", *args)

assert result.exit_code == 1, result.output
assert result.output == helpers.dedent(
"""
No environments were selected
"""
)

assert env_run.call_args_list == []


class TestShow:
def test_default_compact(self, hatch, temp_dir, config_file, helpers):
Expand Down