mesonbuild / meson-python

Meson PEP 517 Python build backend
https://mesonbuild.com/meson-python/
MIT License
125 stars 65 forks source link

Meson editable install: `pytest --pyargs` does not collect any tests #568

Closed lesteve closed 7 months ago

lesteve commented 8 months ago

To reproduce

mkdir -p ~/venvs
rm -rf ~/venvs/test-env
python -m venv ~/venvs/test-env
pip install scipy joblib threadpoolctl cython meson-python ninja pytest
git clone https://github.com/scikit-learn/scikit-learn --depth 1
cd scikit-learn
make dev-meson
# go outside of repo root (with pytest 8 it fails also in the repo root)
cd
pytest --pyargs sklearn --collect-only

Output shows "no tests collected in 0.10s". Without --pyargs, this works fine, pytest sklearn --collect-only shows ~33k tests.

I checked that numpy has the same issue, so this is not specific to scikit-learn

Could this be related to https://github.com/mesonbuild/meson-python/issues/557? ~I have to check I haven't taken the time to confirm it yet.~ Actually I checked with @ogrisel branch from https://github.com/mesonbuild/meson-python/pull/562 and it seems to collect tests fine, so this seems related.

Full disclosure: with pytest<8, tests are collected if you stay in the repo root. I believe this is kind of by chance, since pytest 8 has introduced collection behaviour changes/fixes see https://docs.pytest.org/en/stable/changelog.html#collection-changes for more details.

rgommers commented 8 months ago

Thanks for the report @lesteve. Hmm, that looks a little annoying. pytest 8.0 was only released 4 days ago, so I didn't notice this yet. And I probably wouldn't have anyway, since pytest numpy is more typical usage. It'd be nice to fix though, since this is the type of little paper cut that makes editable installs less pleasant to use.

lesteve commented 8 months ago

Yep agreed, I may try to look at #562 and understand a bit more the subtle things behind Python import mechanisms.

QuLogic commented 7 months ago

I wonder if this is the same reason we had to do this (pytest's assertion rewriting didn't work in editable installs unless using import-mode=importlib)?

rgommers commented 7 months ago

@QuLogic interesting. I'm not sure if that's indeed due to the same reason, but it'd be interesting to know if the improvement to editable installs that was just merged makes a difference.