6

pytest 如何跨目录调用 conftest

 2 years ago
source link: https://www.v2ex.com/t/844075
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

pytest 如何跨目录调用 conftest

  css3 · 14 小时 58 分钟前 · 180 次点击

如何在不调整目录结构的前提下能让A目录下的conftest.py, 使用B或者C目录下的conftest.py内的fixture函数

# 目录结构
.
├── A
│   ├── conftest.py
│   ├── __init__.py
│   └── test_A.py
├── B
│   ├── conftest.py
│   └── __init__.py
├── C
│   ├── conftest.py
│   └── __init__.py
├── D
└── E
# ./A/conftest.py
pytest_plugins = [
    "..B.conftest",
    "..C.conftest"
  ]
$ pytest test_A.py
# 报错: ImportError: Error importing plugin "..B.conftest": No module named '.'


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK