python-3.x - Pytest - 测试用例执行顺序

标签 python-3.x pytest qa

我有一些带有测试的脚本,我需要在 中运行这些测试我明确定义的执行顺序 .

看起来像:

# one.py
import some lib

class Foo():
    def makesmth(self)
        script

然后我制作了测试文件:
# test_one.py
import pytest
import some lib

class TestFoo():
    def test_makesmth(self):
        try/except/else assert etc.

所以它看起来简单而正确。当我运行文件 test_one.py 时一切正常。
我的脚本测试包看起来像:
package/
|-- __init__.py
|-- scripts
|   |-- one.py
|   |-- two.py
|-- tests
|   |-- test_one.py
|   |-- test_two.py

当我尝试收集测试时
pytest --collect-only

它给出了非字母顺序和随机的测试顺序。

我可以在哪里写有关测试顺序的信息?非字母顺序,就像我想像 b、a、c、e、d 一样开始测试 - 不是随机的,不是按字母顺序的

试图制作文件tests.py:
import pytest

from tests.test_one import TestFoo
from tests.test_two import TestBoo etc.

当我尝试运行它时,会显示错误,因为这些导入是以我不理解的方式完成的(试图使 a TestFoo b TestBoo 并重命名以这种方法定义方式测试文件,但它仍然不起作用)。

对不起,如果我的问题看起来不专业,我是初级问答,几乎没有自动测试经验。

最佳答案

您可以使用 pytest-ordering

https://pytest-ordering.readthedocs.io/en/develop/

import pytest
@pytest.mark.run(order=1)
def test_first():
    pass
@pytest.mark.run(order=2)
def test_second():
    pass

test_sample.py::test_first PASSED
test_sample.py::test_second PASSED

关于python-3.x - Pytest - 测试用例执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53887011/

相关文章:

python - Healpy 在 Windows 上安装 Python 3.4

python - TypeError : “' int' object is not callable”, 'occurred at index 0'

python-3.x - 通过 Pytest 和 Requests 测试 Django 时 MissingSchema 错误

unit-testing - 由 QA 工程师进行的单元测试

python - 得到一个无类型错误的Python 3?

python - 在没有 Tee 的情况下在 Python 中克隆生成器

python - 在 Python 中寻找片状测试的根本原因

python - 如何使用每个模块的测试数据初始化数据库? Pytest-django

web - 是否有任何工具可以直观地比较两个不同的网页?

javascript - 包含许多断言的 Cypress 测试的最佳实践