pytest - ModuleNotFoundError - python 3.6.4

2024-04-29

我有一个具有以下布局的项目:

├── 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 -m pytest -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'

我还尝试使用以下方法修改 sys.path:

import sys

print(os.path.abspath("."))
sys.path.insert(0, os.path.abspath("."))
print(sys.path)

但我得到了相同的结果。 对此有什么帮助吗?

我在 OS X 10.13.4 上使用 python 3.6.4


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

pytest - ModuleNotFoundError - python 3.6.4 的相关文章

随机推荐