pytest无法使用__init__.py加载测试模块

时间:2019-09-19 09:11:57

标签: python pytest

使用pytest运行特定测试时,出现以下错误:

>>> pytest test/test_app.py
ImportError while importing test module '/home/connesy/code/test/test_app.py'.
Traceback:
test/test_app.py:3: in <module>
    import __init__
E   ModuleNotFoundError: No module named '__init__'

我的代码的结构如下:

├── src
│   ├── __init__.py
│   ├── conftest.py  # Empty
│   ├── app.py
│   ├── server.py
├── test
│   ├── __init__.py
│   ├── test_app.py
│   ├── test_server.py

每个测试的顶部都有import __init__,而__init__src添加到sys.path

我需要能够从server.py导入和运行测试,因此test必须是一个程序包。如何在具有这种结构的pytest中运行特定的测试?

0 个答案:

没有答案