Running 'hatch test' command, default matrix does not respect 'requires-python'
Discussed in https://github.com/pypa/hatch/discussions/1568
I have one project with requires-python = ">=3.8", and running hatch test works — the project gets installed in the 'hatch-test.py3.11' environment, so the imports within my test modules work.
A second project has requires-python = ">=3.12", and running hatch test doesn't create a new 'hatch-test.py3.12' environment and install the project in it, so the tests error out.
I thought changing requires-python to ">=3.11" in the second project might make hatch test go ahead and install the project in the existing 3.11 hatch-test environment, but it didn't. But running hatch test -py 3.12 created a new 3.12 test environment and worked.
Thank you, I will fix this!
Thank you for hatch — I'm into it!
I'm fairly new to hatch so it could be a usage error but I think I am facing the same issue.
In our pyproject.toml we have:
[project]
# metadata
requires-python = ">=3.9"
# more metadata
[[tool.hatch.envs.all.matrix]]
python = ["3.9", "3.10", "3.11", "3.12"]
There are no other mention of python version in the pyproject.toml file.
On running
hatch test --all
The tests do indeed run for py3.13 to py3.9 but additionally at the end it also prints out:
Skipped 1 incompatible environment:
hatch-test.py3.8 -> cannot locate Python: 3.8
You can find the full pyproject file here
I used to have 3.8 in the matrix, in case that is relevant.
@ofek what’s the plan here:
- do you just plan to fix the case where hatch tries to create an env that can’t work, or
- do you plan to make the default matrix dynamic so it doesn’t contain entries for Python versions that don’t match
requires_python?
The latter.
Very cool!