Skip to content

Pytest runner removal

The use of make test is a easy and simple way out, as the documented ways in Python package guidelines#Check didn't work out of the box. However, make test it is not the most optimized way.

Here are my attempts and details:

Calling pytest directly, failed

Calling pytest or PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-$python_version" pytest fail with the following output:

_____________________ ERROR collecting test/test_plyvel.py _____________________
ImportError while importing test module '/build/python-plyvel/src/plyvel-1.5.0/test/test_plyvel.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test/test_plyvel.py:17: in <module>
    import plyvel
plyvel/__init__.py:6: in <module>
    from ._plyvel import (  # noqa
E   ModuleNotFoundError: No module named 'plyvel._plyvel'

Calling make test, successful

make test uses the instructions in the project's Makefile. Calling test runs the following workflow of make targets: cython -> ext -> test. cython was already called in build() so this is a duplicated called that would be nice to avoid. ext basically runs python setup.py build_ext, and this tasks is also accomplished by PyPA build command python -m build. test simply runs pytest.

The difference between make ext and python -m build is that the latter does not copy the extension module generated (_plyvel.cpython-311-x86_64-linux-gnu.so) from build/ to plyvel/ and this cases pytest to fail in the above attempts.

Alternative: Copy so into plyvel

Another uglier check() but with less duplicate builds would be to copy the built extension to the package directory "plyvel":

check() {
  cd plyvel-$pkgver
  python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  cp build/lib.linux-$CARCH-cpython-$python_version/plyvel/_plyvel.*.so plyvel/
  pytest

TODOs related: pytest-runner removal, Stop using python setup.py test

Edited by Rafael Fontenelle

Merge request reports