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
Extensionfor theext_modulesto include the Cython.pyxfiles, do not usedistutils.extension.Extensionbut 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
cythonizefunction, 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
Extensionfor your.pyxmodule, make sure the name of theExtensionis identical to the name of the module (so name it 'calculateScore' and not for instance 'package.calculateScore').delete the compiled
.sofile corresponding to your.pyxfile and then re-run.
Post a Comment for "Pytest Cannot Find Module On Import But Code Runs Just Fine"