繁体   English   中英

pytest 插件相互覆盖

[英]pytest plugins override each other

我写了 2 个类似的插件:

import pytest
@pytest.fixture
def pyplug<ID>_fixture():
    pass

其中<ID>替换为我给插件的编号,即“0”、“1”...

我为每个插件创建了一个 setup.py:

from setuptools import setup
setup(
    name='pyplug<ID>',
    packages=['pyplug<ID>'],
    entry_points={'pytest11': ['pkg = pyplug<ID>.plugin']}
    )

在每个 package 中,我用 plugin.py 文件创建了另一个目录(同名),其中包含前面描述的夹具。

这是我为每个插件运行python setup.py bdist_wheel后的目录树:

src/
├── pyplug0
│   ├── build
│   │   ├── bdist.linux-x86_64
│   │   └── lib
│   │       └── pyplug0
│   │           └── plugin.py
│   ├── dist
│   │   └── pyplug0-0.0.0-py3-none-any.whl
│   ├── pyplug0
│   │   └── plugin.py
│   ├── pyplug0.egg-info
│   │   ├── dependency_links.txt
│   │   ├── entry_points.txt
│   │   ├── PKG-INFO
│   │   ├── SOURCES.txt
│   │   └── top_level.txt
│   └── setup.py
└── pyplug1
    ├── build
    │   ├── bdist.linux-x86_64
    │   └── lib
    │       └── pyplug1
    │           └── plugin.py
    ├── dist
    │   └── pyplug1-0.0.0-py3-none-any.whl
    ├── pyplug1
    │   └── plugin.py
    ├── pyplug1.egg-info
    │   ├── dependency_links.txt
    │   ├── entry_points.txt
    │   ├── PKG-INFO
    │   ├── SOURCES.txt
    │   └── top_level.txt
    └── setup.py

这是我的 pip 冻结:

attrs==19.3.0
importlib-metadata==1.6.0
more-itertools==8.2.0
packaging==20.3
pluggy==0.13.1
py==1.8.1
pyparsing==2.4.7
pyplug0==0.0.0
pyplug1==0.0.0
pytest==5.4.1
pytest-html==2.1.1
pytest-metadata==1.8.0
pytest-tldr==0.2.1
six==1.14.0
wcwidth==0.1.9
zipp==3.1.0

这是我的测试文件内容:

def test_plugin(pyplug0_fixture):
    pass

def test_plugin2(pyplug1_fixture):
    pass

问题是,插件没有注册好。 当我只安装一个(哪个无关紧要)并测试它时,没问题。 当我安装两者时,一个被另一个覆盖,这在 IMO 中没有意义,因为它们有不同的名称(对于夹具和插件)

我在 Ubuntu16.04 上运行 py3.6.10

找到了。 两个 setup.py 都有相同的入口点:

entry_points={"pytest11": ["KEY = VAL"]}

VAL 不同,但我一直使用相同的 KEY,所以最新的总是赢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM