pytest-无法访问父目录中的装置

问题描述 投票:0回答:1

我有以下目录结构,所有内容都在虚拟环境下运行。

- proddir
    |- testdir
         |- test_feature1
              |- test_create.py
         |- conftest.py
    |- libdir
         |- lib_feature1
               |- lib_create.py
    |- conftest.py

当我尝试从

proddir
访问它时,我无法访问
test_create.py
的conftest.py中定义的设备,但当我在lib_create.py

中使用它时能够访问它

尝试添加

__init__.py
以将目录视为所有级别的包,但它也不起作用。

pytest fixtures conftest
1个回答
0
投票

我认为,这是因为你在 testdir 中有另一个 conftest.py 文件。因此它检查 testdir 的 conftest.py 文件,但不检查 proddir。

由于 libdir 不存在这种情况,因此它会检查 proddir 中正确的conftest.py。

© www.soinside.com 2019 - 2024. All rights reserved.