pytest-ModuleNotFoundError-Python3.6.4
我有一个布局如下的项目:pytest-ModuleNotFoundError-Python3.6.4,python,python-3.x,pytest,python-unittest,sys,Python,Python 3.x,Pytest,Python Unittest,Sys,我有一个布局如下的项目: ├── MANIFEST.in ├── README.md ├── __init__.py ├── company │ ├── __init__.py │ ├── api │ │ ├── __init__.py │ │ ├── auth.py │ │ ├── debug.py │ │ ├── exceptions.py │ │ ├── reporting.py │ │ ├── rest.py │ │ ├──
├── MANIFEST.in
├── README.md
├── __init__.py
├── company
│ ├── __init__.py
│ ├── api
│ │ ├── __init__.py
│ │ ├── auth.py
│ │ ├── debug.py
│ │ ├── exceptions.py
│ │ ├── reporting.py
│ │ ├── rest.py
│ │ ├── soap.py
│ │ └── utils.py
│ ├── jinjaEnvironment.py
│ ├── sql
│ │ ├── __init__.py
│ │ ├── connection.py
│ │ └── sql_helper.py
│ └── templates
│ ├── __init__.py
│ ├── getUser.xml
│ ├── rest_write_custom_field.xml
│ └── setUser.xml
├── company.egg-info
├── requirements.txt
├── setup.py
└── tests
├── __init__.py
└── test_api.py
使用python-m unittest-v(从项目根文件夹启动),测试运行良好。
我试图安装并使用pytest,但迄今为止没有成功。截至nwo,我尝试:
pytest
python-mpytest-v
ImportError while importing test module '/Users/my.user/PycharmProjects/company/tests/test_api.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_api.py:22: in <module>
from company.api import auth, reporting, exceptions as api_exceptions
E ModuleNotFoundError: No module named 'company.api'
但我得到了同样的结果。
有什么帮助吗
我正在OS X 10.13.4上使用python 3.6.4尝试添加。。导入模块前面:from..company.api…….它可以工作但会中断
python-m unittest
:ValueError:尝试在顶级包之外进行相对导入
更多可用的回溯?使用pip安装--可编辑。
然后pytest
(都来自包含setup.py
文件的目录)。从tests subdir中删除\uuuu init\uuuuuuuuuupy
文件,它不应该在那里。无论您将此sys.path.insert
垃圾放在何处,也要删除所有垃圾。正确的命令只是pytest
,正确的导入路径是company.api
,正如回溯中已经看到的那样。确保pytest
处于安装在与软件包相同的环境中(。
),并且您没有意外使用安装在系统站点软件包中的pytest。
import sys
print(os.path.abspath("."))
sys.path.insert(0, os.path.abspath("."))
print(sys.path)