MAINT: Update to spin 0.12
Can someone check if https://github.com/numpy/numpy/pull/27371/commits/f6680e44a1bbd0085fc012c9acfefa95c6b58dc1 is acceptable?
Doctests are failing badly.
Is it possible that spin invoking pytest with --import-mode=importlib is why the relative imports are suddenly failing? Pytests documentation states that for that mode
Test modules can’t import each other.
Without checking every file, it seems to me that this is the only place where spin test is used; other passing workflows seem to use pytest directly.
That option is added by spin if not already given and was added in https://github.com/scientific-python/spin/commit/e8e8943384fe973fe6b287a42954735d179f1edb (v11-v12).
@lagru Can you replicate the problem on your system? I can't.
close/reopen
I can reproduce the problem with spin 0.12 for the numpy.f2py tests, as well as for SciPy in the in-progress work to move to spin (xref https://github.com/scientific-python/spin/pull/238#discussion_r1834428942).
@lagru's explanation about --import-mode above seems very plausible.
I would prefer we have a local override for the
spin testcommand that will work around the shortcomings of the globalspin testpytest invocation.
I tend to agree. Forbidding relative imports is an annoying limitation, and the failure mode is very obscure. So far we've been able to support test layouts with relative imports just fine in both NumPy (with older spin) and with SciPy (with dev.py), while also supporting editable installs + direct pytest invocation.
It seems to me like it should be feasible to handle this within spin either automatically or at most by adding a single config (e.g. path-to-package-root = 'numpy') in pyproject.toml.
The importlib change is the reason, yes:
importlib: new in pytest-6.0, this mode uses importlib to import test modules. This gives full control over the import process, and doesn’t require changing sys.path.
For this reason this doesn’t require test module names to be unique.
One drawback however is that test modules are non-importable by each other. Also, utility modules in the tests directories are not automatically importable because the tests directory is no longer added to sys.path.
Initially we intended to make importlib the default in future releases, however it is clear now that it has its own set of drawbacks so the default will remain prepend for the foreseeable future.
We could add the path-to-package-route option; it should be obvious in most cases (you typically either have a modulename or a src directory; if both exist, can exit with advice on what the user needs to do.
Will open a new PR for spin 0.13.