Skip to main content
 首页 » 编程设计

python之Flask 中的 Selenium 测试优先级

2024年11月24日14qlqwjy

我在 selenium 中有一个用例,其中测试函数的优先级很重要。我在 Flask 中使用 LiveServerTestCase 进行测试。 在 Java 中,有一个装饰器 @Test(priority=0) 用于定义测试优先级。我的问题是 Flask 中的等价物是什么?

请您参考如下方法:

这可能无法回答您的问题,因为我对 LiveServerTestCase 没有任何知识或经验,我更像是一个 pytest 人,如果您走上 pytest 之路,请查找

https://github.com/ftobia/pytest-ordering/blob/develop/docs/source/index.rst

import pytest 
 
@pytest.mark.order2 
def test_foo(): 
    assert True 
 
@pytest.mark.order1 
def test_bar(): 
    assert True 

话虽如此,我查看了 flask 测试文档(我假设您正在使用此扩展),它支持 Nose 收集器和测试运行器。

https://flask-testing.readthedocs.io/en/latest/#with-nose

并且根据 nose 文档,测试按照它们在测试模块文件中定义的顺序运行。

https://nose.readthedocs.io/en/latest/writing_tests.html#writing-tests

您可以利用 nose 测试运行器。再次抱歉,这篇文章对您没有帮助。