• 请不要在回答技术问题时复制粘贴 AI 生成的内容
css3
V2EX  ›  程序员

pytest 如何跨目录调用 conftest

  •  
  •   css3 · Mar 31, 2022 · 1190 views
    This topic created in 1513 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   ·   1138 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 23:37 · PVG 07:37 · LAX 16:37 · JFK 19:37
    ♥ Do have faith in what you're doing.