hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Running 'hatch test' command, default matrix does not respect 'requires-python'

Open hobbsd opened this issue 1 year ago • 6 comments

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.

hobbsd avatar Jun 14 '24 14:06 hobbsd

Thank you, I will fix this!

ofek avatar Jun 14 '24 14:06 ofek

Thank you for hatch — I'm into it!

hobbsd avatar Jun 14 '24 15:06 hobbsd

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.

harsh-at-ikigailabs avatar Dec 10 '24 04:12 harsh-at-ikigailabs

@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?

flying-sheep avatar Apr 14 '25 08:04 flying-sheep

The latter.

ofek avatar Apr 14 '25 14:04 ofek

Very cool!

flying-sheep avatar Apr 15 '25 15:04 flying-sheep