pytest - ModuleNotFoundError - python 3.6.4

本小妞迷上赌 提交于 2019-12-10 17:54:22

问题


I have a project with this layout:

├── 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

with python -m unittest -v (launched from the project root folder), tests runs fine. I tried to install and use pytest, so far without success. As of nwo I tried:

  • pytest
  • python -m pytest -v

but I get the same error:

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'

I also tried to modify sys.path with:

import sys

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

but I got the same results. Any help on this?

I'm using python 3.6.4 on OS X 10.13.4

来源:https://stackoverflow.com/questions/49723266/pytest-modulenotfounderror-python-3-6-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!