Pytest Cannot Find Module On Import But Code Runs Just Fine
Solution 1:
I have no idea why this is happening, but for me the easiest solution was to use the pytest-cython
approach and change one or multiple things listed below in the package's setup.py
file:
- when defining your
Extension
for theext_modules
to include the Cython.pyx
files, do not usedistutils.extension.Extension
but rather usesetuptools.Extension
The reason why I manually create an Extension
instead of using the Cython.Build.cythonize
function, is not important here. But please note that for the pytest-runner
approach:
- do not use the
cythonize
function, but create the Extension manually
After writing this post I cannot even seem to reproduce the problem using pytest-cython
anymore, which suggests that maybe something else is the cause of the problem. An additional thing you could try is to make sure that:
when manually creating an
Extension
for your.pyx
module, make sure the name of theExtension
is identical to the name of the module (so name it 'calculateScore' and not for instance 'package.calculateScore').delete the compiled
.so
file corresponding to your.pyx
file and then re-run.
Post a Comment for "Pytest Cannot Find Module On Import But Code Runs Just Fine"