'ModuleNotFoundError when running pytest and tox
I am trying to build template packages for 2 slightly different purposes, they can be found here :
- https://github.com/martinlanton/tox_template_project
- https://github.com/martinlanton/maya_template_project
The first one is a generic template project using tox/pytest/setup.py and works quite fine. The second one however is for the same purpose but when testing with the interpreter provided with Autodesk Maya.
My problem comes with the second one.
When running the tests using the tox command, I get this error :
______________________________________________________________________________________________________________ ERROR collecting tests/test_maya_test_setup.py ______________________________________________________________________________________________________________
ImportError while importing test module 'D:\python\maya_template_project\tests\test_maya_test_setup.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Program Files\Autodesk\Maya2022\Python37\lib\importlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests\test_maya_test_setup.py:4: in <module>
from one.module_one import create_sphere
E ModuleNotFoundError: No module named 'one'
========================================================================================================================= short test summary info ==========================================================================================================================
ERROR tests/test_maya_test_setup.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================================= 1 error in 0.13s =============================================================================================================================
ERROR: InvocationError for command 'C:\Program' 'Files\Autodesk\Maya2022\bin\mayapy' -m pytest (exited with code 2)
_________________________________________________________________________________________________________________________________ summary __________________________________________________________________________________________________________________________________
ERROR: maya2022: commands failed
Here is the content of my tox.ini :
[tox]
envlist = maya2022
skipdist = True
[testenv:maya2022]
passenv = PYTHONPATH
deps = -rrequirements.txt
commands =
C:\Program Files\Autodesk\Maya2022\bin\mayapy -m pytest
setenv =
IN_MAYA = 1
As far as I understand, this seems to come from the location of the conftest.py, which forces tox to add the location of the conftest file to sys.path.
I have tried to remove the skipdist as mentioned in a few threads, but this had no effect whatsoever on the result (as I suspected anyway, because of the work around mentioned below).
This means that if I update this line to from src.one.module_one import create_sphere, this fixes the problem and works properly.
However, this is very undesirable as I do not want the src package to be importable, but more importantly, I'd like the one package to be importable directly as this is the most logical thing to do, but also because this is the intended behavior as explained in this article.
So my question is : how do I fix this and get my project working without needing to add the src package to my imports?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
