Bug: cannot run tests with an editable installation of `pyWavelets`, possible `pytesttester` test collection discrepancy?
Description
Hi, I'm trying to run the test suite using pytest against an editable installation of pyWavelets/pywt, and it looks like the PytestTester class in the pywt/_pytesttester.py module is not configured to run against on editable installations (with the -e . command-line flag) in the same way it seems to run in CI for non-editable installations (pip install .)
MWE, i.e., steps to reproduce
In a terminal, run
pip install numpy==1.23.3 cython meson-python # Python 3.11, build-time requirements sourced from the build-system table in pyproject.toml
pip install -e .
pip install pytest
and then,
pytest --pyargs pywtdoes not work and returns the following trace:
Expand to view logs
====================================================================== test session starts ======================================================================
platform darwin -- Python 3.11.7, pytest-8.0.1, pluggy-1.4.0
rootdir: /Users/agriyakhetarpal/Desktop/Work/pywt
configfile: pytest.ini
collected 0 items / 1 error
============================================================================ ERRORS =============================================================================
_______________________________________________________________ ERROR collecting pywt/__init__.py _______________________________________________________________
venv/lib/python3.11/site-packages/pluggy/_hooks.py:501: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
firstresult = True
kwargs = {'collector': <Module __init__.py>, 'name': 'test', 'obj': <pywt._pytesttester.PytestTester object at 0x1068ad7d0>}
self = <HookCaller 'pytest_pycollect_makeitem'>
venv/lib/python3.11/site-packages/pluggy/_manager.py:119: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
firstresult = True
hook_name = 'pytest_pycollect_makeitem'
kwargs = {'collector': <Module __init__.py>, 'name': 'test', 'obj': <pywt._pytesttester.PytestTester object at 0x1068ad7d0>}
methods = [<HookImpl plugin_name='python', plugin=<module '_pytest.python' from '/Users/agriyakhetarpal/Desktop/Work/pywt/venv/l...test.unittest' from '/Users/agriyakhetarpal/Desktop/Work/pywt/venv/lib/python3.11/site-packages/_pytest/unittest.py'>>]
self = <_pytest.config.PytestPluginManager object at 0x105633550>
venv/lib/python3.11/site-packages/_pytest/python.py:260: in pytest_pycollect_makeitem
warnings.warn_explicit(
E pytest.PytestCollectionWarning: cannot collect 'test' because it is not a function.
collector = <Module __init__.py>
filename = PosixPath('/Users/agriyakhetarpal/Desktop/Work/pywt/pywt/_pytesttester.py')
lineno = 72
name = 'test'
obj = <pywt._pytesttester.PytestTester object at 0x1068ad7d0>
==================================================================== short test summary info ====================================================================
ERROR pywt/__init__.py - pytest.PytestCollectionWarning: cannot collect 'test' because it is not a function.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
With pywt.test(), there is another error on editable installations:
113 import pytest
115 module = sys.modules[self.module_name]
--> 116 module_path = os.path.abspath(module.__path__[0])
118 # setup the pytest arguments
119 pytest_args = ["-l"]
IndexError: list index out of range
Workarounds
However, for now,
pytest .,pytest pywt
seem to work as usual and proceed with the collection of 1036 tests in total. These commands have been tested in a fresh, virtualenv-based virtual environment with Python 3.11.7 on a macOS M-series machine.
Additional notes
The bug seems to be coming from the --pyargs configuration in pywt/_pytesttester.py here:
https://github.com/PyWavelets/pywt/blob/e69b126c096868b0ea7650d38ed11cd95a9dc182/pywt/_pytesttester.py#L150-L156
which I'm not totally sure about, but it seems to be searching for test inside pywt/__init__.py as an importable Python module – while it is an instance of the PytestTester class.
Thanks for the report @agriyakhetarpal. I believe the second error (IndexError from pywt.test()) will be resolved by https://github.com/mesonbuild/meson-python/pull/569. Could you please confirm that?
Thanks for the resource! I installed the changes made in the PR via
pip install git+https://github.com/dnicolodi/meson-python.git@editable-module-path
and recompiled with meson-python (version 0.16.0dev0) via pip install -e . --no-build-isolation, and now all of the three commands, i.e.,
pytest/pytest ./pytest pywtpytest --pyargs pywt, andpython -c "import pywt; pywt.test()"
are working on editable installations of pywt. I can confirm that https://github.com/mesonbuild/meson-python/pull/569 resolves the issue entirely.
Awesome. Then I'll focus on getting that merged and released, and once that is out in meson-python 0.16.0, we can close this issue.