IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发测试 -> Pytest 不同文件的执行顺序 -> 正文阅读

[开发测试]Pytest 不同文件的执行顺序

引言
  unittest框架和pytest框架编写的测试用例执行顺序,默认根据ACSII码的顺序加载测试用例,数字与字母的顺序为:0~9,A~Z,a~z。

  1.对于类来说,class TestAxx 会优先于class TestBxx被执行。

  2.对于方法来说,test_aaa()方法会有优先于test_bbb()被执行。

????????3.对于方法来说,test_01()方法会优先test_aa执行

  对于测试目录与测试文件来说,unittest同样是按照这个规则来加载测试用例的。
没有排序执行:

import pytest

class Test_Pytest():
    @classmethod
    def setUpClass(cls):
        print("setup_class方法执行1次")
    @classmethod
    def tearDownClass(cls):
        print("teardown_class方法执行1次")

    def setup(self):
        print("setup 第多次")
    def teardown(self):
        print("teardown 第多次")

    def setup_method(self):
        print("setup_method方法执行多次")

    def teardown_method(self):
        print("teardown_method方法执行多次")
?   def test_two(self):
        print('test2')

    def test_one(self):
        print('test1')

    def test_1(self):
        print('testb')

    def test_a(self):
        print('testa')

if __name__=="__main__":
    pytest.main(['-s -v','test_class.py'])
    pytest.main()

结果:

test_class.py::Test_Pytest::test_two setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ 25%]test2
teardown 第多次
teardown_method方法执行多次test_class.py::Test_Pytest::test_one setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ 50%]test1
teardown 第多次
teardown_method方法执行多次
test_class.py::Test_Pytest::test_1 setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ 75%]testb
teardown 第多次
teardown_method方法执行多次

test_class.py::Test_Pytest::test_a setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[100%]testa
teardown 第多次
teardown_method方法执行多次
?

改用例执行顺序的插件
通过@pytest.mark.run(order=1)控制执行顺序

import pytest

class Test_Pytest():
    @classmethod
    def setUpClass(cls):
        print("setup_class方法执行1次")
    @classmethod
    def tearDownClass(cls):
        print("teardown_class方法执行1次")

    def setup(self):
        print("setup 第多次")
    def teardown(self):
        print("teardown 第多次")

    def setup_method(self):
        print("setup_method方法执行多次")

    def teardown_method(self):
        print("teardown_method方法执行多次")
????def test_two(self):
        print('test2')

    @pytest.mark.run(order=2)
    def test_one(self):
        print('test1')
    @pytest.mark.run(order=1)
    def test_1(self):
        print('testb')

    def test_a(self):
        print('testa')

if __name__=="__main__":
    pytest.main(['-s -v','test_class.py'])

结果:

test_class.py::Test_Pytest::test_1 setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ 25%]testb
teardown 第多次
teardown_method方法执行多次

test_class.py::Test_Pytest::test_one setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ 50%]test1
teardown 第多次
teardown_method方法执行多次

test_class.py::Test_Pytest::test_two setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[ 75%]test2
teardown 第多次
teardown_method方法执行多次

test_class.py::Test_Pytest::test_a setup_method方法执行多次
setup 第多次
PASSED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[100%]testa
teardown 第多次
teardown_method方法执行多次
?

?

  开发测试 最新文章
pytest系列——allure之生成测试报告(Wind
某大厂软件测试岗一面笔试题+二面问答题面试
iperf 学习笔记
关于Python中使用selenium八大定位方法
【软件测试】为什么提升不了?8年测试总结再
软件测试复习
PHP笔记-Smarty模板引擎的使用
C++Test使用入门
【Java】单元测试
Net core 3.x 获取客户端地址
上一篇文章      下一篇文章      查看所有文章
加:2021-07-22 23:05:08  更:2021-07-22 23:05:34 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/1 21:28:54-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码