python - 如何将 1 pytest.mark 内容的内容复制到另一个

标签 python pytest

我想将一个标记的内容复制到另一个标记。

例如: 我有一个标记,pytest.mark.mini,这个标记有一些测试。现在我已经创建了另一个名为 pytest.mark.integration 的标记,这个标记将有“迷你”和一些更多的测试。

我想将迷你标记内容复制到集成标记。我该怎么做这个复制。

谢谢

最佳答案

您可以动态添加标记,例如在 pytest_collection_modifyitems 中钩。将下面的代码放在项目目录的 conftest.py 中:

import pytest

def pytest_collection_modifyitems(items):
    for item in items:
        if item.get_closest_marker('mini') and not item.get_closest_marker('integration'):
            item.add_marker(pytest.mark.integration)

并且每个标有@pytest.mark.mini的测试也将标有@pytest.mark.integration

关于python - 如何将 1 pytest.mark 内容的内容复制到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57437156/

相关文章:

python - 从 Python 脚本运行 Maven 的方法?

python - 为什么在没有Except block 的情况下Python仍会引发异常?

python - Pytest 和 Python 3

python - tox+pytest 仅在 travis 上给出调用错误,代码为 -11

python - Pytest 适用于旧模拟,但不适用于 unittest.mock

python - 从另一个 pip 安装的包针对本地代码运行 py.test 测试

python - pandas 在多索引级别匹配上减去

python - 如何使用 spacy_langdetect 包中的 LanguageDetector()?

python - 如何在 Python Flask 应用程序中存储环境变量?

python - pytest-django 找不到 Django 项目