Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: cannot run tests with an editable installation of pyWavelets, possible pytesttester test collection discrepancy? #700

Closed
agriyakhetarpal opened this issue Feb 21, 2024 · 3 comments · Fixed by #702

Comments

@agriyakhetarpal
Copy link
Collaborator

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,

  1. pytest --pyargs pywt does 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,

  1. pytest .,
  2. 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:

pywt/pywt/_pytesttester.py

Lines 150 to 156 in e69b126

if tests is None:
tests = [self.module_name]
pytest_args += ["--pyargs"] + list(tests)
# run tests.

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.

@rgommers
Copy link
Member

Thanks for the report @agriyakhetarpal. I believe the second error (IndexError from pywt.test()) will be resolved by mesonbuild/meson-python#569. Could you please confirm that?

@agriyakhetarpal
Copy link
Collaborator Author

agriyakhetarpal commented Feb 22, 2024

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.,

  1. pytest / pytest . / pytest pywt
  2. pytest --pyargs pywt, and
  3. python -c "import pywt; pywt.test()"

are working on editable installations of pywt. I can confirm that mesonbuild/meson-python#569 resolves the issue entirely.

@rgommers
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants