python - 测试套件的 Pytest 排序

标签 python amazon-web-services pytest

我有一组用于不同 UI 测试的测试文件(.py 文件)。 我想使用 pytest 按特定顺序运行这些测试文件。我使用了下面的命令

python -m pytest -vv -s --capture=tee-sys --html=report.html --self-contained-html ./Tests/test_transTypes.py ./Tests/test_agentBank.py ./Tests/test_bankacct.py

pytest 执行是由 AWS Batch 作业触发的。 当测试执行发生时,它不会按照上述命令中指定的顺序执行测试文件。 相反,它首先运行 test_agentBank.py,然后运行 ​​test_bankacct.py,然后运行 ​​test_transTypes.py 每个 python 文件都包含一堆测试函数。

我还尝试装饰测试函数类,例如第一个python文件(test_transTypes.py)中的@pytest.mark.run(order=1),第二个python中的@pytest.mark.run(order=2)文件(test_agentBank.py)等。 这似乎按顺序运行测试,但最后我收到警告

 PytestUnknownMarkWarning: Unknown pytest.mark.run - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs
.pytest.org/en/stable/how-to/mark.html
    @pytest.mark.run(order=1)

在 pytest 中按特定顺序运行测试的正确方法是什么? 我的每个“test_”python 文件都是我需要使用 pytest 运行的文件。

非常感谢任何帮助。

最佳答案

要指定 pytest 中运行测试的顺序,可以使用 pytest-order插入。该插件允许您通过提供 order 标记来自定义测试运行的顺序,该标记具有定义测试何时应相对彼此运行的属性。您可以使用绝对属性(例如,第一个、倒数第二个)或相对属性(例如,在另一个测试之前运行此测试)来指定测试的顺序。这是一个例子:

import pytest

@pytest.mark.order(2)
def test_foo():
    assert True

@pytest.mark.order(1)
def test_bar():
    assert True

关于python - 测试套件的 Pytest 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75598463/

相关文章:

angularjs - 将所有 AWS S3 http 请求重定向到 AngularJS HTML5Mode 的 index.html

python - Mixer.blend() 模块无法正确创建引用 UUID 作为 PK 的自定义用户对象的实例

python - 是否可以从 pandas 库中读取源代码并在我自己的函数中使用它?

ios - 使用 DynamoDB -> 未找到资源

python - 由 moviepy 创建的视频无法在网络上播放

python - 如何在不编写代码的情况下在 amazon sqs 中实现指数退避

python - 确保 py.test 在 sys.path 中包含应用程序目录

python - py.test 不收集不是从 'object' 继承的测试

python - selenium 通过 python 中的可见文本进行选择

python - 基于条件的数据子集的 Fuzzywuzzy