问题
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