gpt4 book ai didi

python-3.x - pytest-ordering 相对顺序不起作用?

转载 作者:行者123 更新时间:2023-12-04 09:28:29 25 4
gpt4 key购买 nike

我想按顺序运行一些测试,我按照官方文章使用 pytest-ordering,但顺序根本没有改变?

import pytest

@pytest.mark.run(after='test_second')
def test_third():
assert True

def test_second():
assert True

@pytest.mark.run(before='test_second')
def test_first():
assert True
应该是 test_first, test_second, test_third命令。
但是顺序根本没有改变???
E:\QT-learn>pytest -svv
============================================================================= test session starts =============================================================================
platform win32 -- Python 3.7.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- c:\users\jekoie\appdata\local\programs\python\python37-32\python.exe
cachedir: .pytest_cache
rootdir: E:\QT-learn, inifile: pytest.ini
plugins: ordering-0.6
collected 3 items

test_qt.py::test_third PASSED
test_qt.py::test_second PASSED
test_qt.py::test_first PASSED

============================================================================== 3 passed in 0.04s ==============================================================================

E:\QT-learn>

最佳答案

documentation pytest-ordering 有一章名为“Aspirational”,并附有以下注释:

This section is for functionality I’d like to implement. Documentation-driven design :)

before的用法和 after属于这一类。
您必须改用已实现的功能:
import pytest

@pytest.mark.run(order=3)
def test_third():
assert True

@pytest.mark.run(order=2)
def test_second():
assert True

@pytest.mark.run(order=1)
def test_first():
assert True
另请注意,文档中描述的方法(使用 @pytest.mark.order1 等)不适用于当前版本 - 正确的版本是 README 中的版本。 .有一个 pull request这将修复文档,但该项目似乎不再维护。
更新:
现在有一个 pull request这将增加对 before/after 语法的支持。

关于python-3.x - pytest-ordering 相对顺序不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62931334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com