V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
css3
V2EX  ›  程序员

pytest 如何跨目录调用 conftest

  •  
  •   css3 · Mar 31, 2022 · 1158 views
    This topic created in 1492 days ago, the information mentioned may be changed or developed.

    如何在不调整目录结构的前提下能让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 '.'
    
    
    1 replies    2022-04-01 08:32:56 +08:00
    luckyc
        1
    luckyc  
       Apr 1, 2022
    python 每日一问 import

    test_A.py 放到上一级去
    from b.conftest import fixture
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2141 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 00:48 · PVG 08:48 · LAX 17:48 · JFK 20:48
    ♥ Do have faith in what you're doing.