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/ _____________________
ImportError while importing test module '/build/python-plyvel/src/plyvel-1.5.0/test/'.
Hint: make sure your test modules/packages have valid Python names.
/usr/lib/python3.11/importlib/ in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test/ in <module>
    import plyvel
plyvel/ 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 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 ( 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/

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

Edited by Rafael Fontenelle

Merge request reports