问题
pytest报错ModuleNotFoundError No module named ‘extensions’
___________________________________________________________________________________________________________________________________ ERROR collecting tests/extensions/test_utils.py ___________________________________________________________________________________________________________________________________
ImportError while importing test module 'D:\institution-service-agent\tests\extensions\test_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Program Files\Python39\lib\importlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests\extensions\test_utils.py:3: in <module>
from extensions import utils
E ModuleNotFoundError: No module named 'extensions'
解决方法
在pycharm中是可以正常运行的,但是在terminal中报错,看网上好多都说找不到搜索路径,但是我加了也不行。后来发现是虚拟环境的问题,
pytest -vv
Hint: make sure your test modules/packages have valid Python names.
这个提示提醒了我 后面使用python -m pytest可以正常运行了
PS D:\institution-service-agent> python -m pytest -vv
================================================================================================================================================= test session starts =================================================================================================================================================
platform win32 -- Python 3.9.7, pytest-7.1.1, pluggy-1.0.0 -- D:\institution-service-agent\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\institution-service-agent
plugins: anyio-3.5.0, mock-3.7.0
collected 3 items
tests/extensions/test_utils.py::test_execute_shell_script_with_unexpected_error PASSED [ 33%]
tests/extensions/test_utils.py::test_execute_shell_script_with_timeout PASSED [ 66%]
tests/extensions/test_utils.py::test_execute_shell_script_with_called_process_error PASSED [100%]
================================================================================================================================================== 3 passed in 0.17s ==================================================================================================================================================
P
|