pytest报错ModuleNotFoundError No module named ‘extensions‘

问题

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pchaoda

感谢支持~~~~~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值