首页 > 解决方案 > Pytest:无论标记如何,如何在所有其他测试之后运行一些测试

问题描述

我有带有标记的测试组:“烟雾”

@pytest.mark.smoke
def test_add_data_source():
.....

@pytest.mark.smoke
def test_del_data_source():
.....

我使用以下命令开始测试:

pytest --strict -s -v -m smoke --alluredir=allure-results

没关系,一切正常。

现在我需要在所有测试完成后将我的 Allure 文件复制到 Allure Report 服务到 Kubernetes 中。这需要在任何情况下运行,与使用的标记无关。我使用了拆解语法:

@pytest.fixture(scope="module",autouse=True)
def global_fixture():
    yield
    send_result()

但在这种情况下,它不会为组中的最后一个测试发送 Allure 文件。但是,如果我使用这样的附加测试 - 它会起作用:

@pytest.mark.smoke
def test_global_fixture():
    send_result()

但无论标记的任何过滤器如何,我都需要运行此测试。在这两个命令的所有其他测试之后应运行 at:

pytest --strict -s -v -m smoke --alluredir=allure-results
pytest --strict -s -v --alluredir=allure-results

我怎样才能做到这一点?

标签: pythonpytestmarkersautotest

解决方案


推荐阅读