百度指数的网站,郑州网站建设公司航迪软件怎么样,网站建设以后主要做什么,智能建站系统的建站步骤简介#xff1a;面对快速迭代和持续交付的需求#xff0c;提高测试效率变得至关重要。并行测试因其显著的时间节省优势而备受青睐。然而#xff0c;并非所有测试都适合并行执行。在某些情况下#xff0c;串行执行是必要的#xff0c;以确保测试的正确性和稳定性。本文将探…简介面对快速迭代和持续交付的需求提高测试效率变得至关重要。并行测试因其显著的时间节省优势而备受青睐。然而并非所有测试都适合并行执行。在某些情况下串行执行是必要的以确保测试的正确性和稳定性。本文将探讨在自动化测试中部分串行、部分并行执行的必要性和实践方法帮助测试开发者在提高测试效率的同时确保测试结果的可靠性和准确性。
安装 pip install pytest-xdistpip install pytest-repeat
使用案例main.py import osimport pytestif __name__ __main__:# step-1use pytest run test_casepytest.main([-s, test_case, -n, auto, --alluredir, ./report])# step-2auto report json datazip to allure-htmlos.system(allure serve report)
test_case/test_demo.py import timeimport unittestclass TestDemo(unittest.TestCase):def test_01(self):time.sleep(5)print(测试用例1执行)def test_02(self):time.sleep(5)print(测试用例2执行)def test_03(self):time.sleep(5)print(测试用例3执行) test_case/test_parallel.py import timeimport pytestclass TestParallel:pytest.mark.repeat(2)def test_parallel_1(self):time.sleep(5)print(Parallel Test 1)pytest.mark.repeat(3)def test_parallel_2(self):time.sleep(5)print(Parallel Test 2)pytest.mark.repeat(1)def test_parallel_3(self):time.sleep(5)print(Parallel Test 3)pytest.mark.repeat(3)def test_parallel_4(self):time.sleep(5)print(Parallel Test 4) test_case/test_serial.py import timeimport pytestpytest.mark.serialclass TestSerial:def test_serial_1(self):time.sleep(5)print(Serial Test 1)def test_serial_2(self):time.sleep(5)print(Serial Test 2)
配置文件pytest.ini # pytest.ini[pytest]markers serial: mark test to run serially
运行结果 注意事项
1、同一文件中混合串行和并行测试并且需要更精细的控制可能需要编写更复杂的自定义逻辑或查找是否有现成的插件能满足这种特定的需求。
2、不关心执行顺序简单地将 -n 参数设置为 auto让 pytest-xdist 插件自动管理并行执行通常是最简单也是最有效的方法。
结论适当拆分错开并行和串行的测试类通过pytest-xdist auto参数可以便捷有效的大幅度提升运行测试用例的效率。
行动吧在路上总比一直观望的要好未来的你肯定会感 谢现在拼搏的自己如果想学习提升找不到资料没人答疑解惑时请及时加入扣群 320231853里面有各种软件测试开发资料和技术可以一起交流学习哦。
最后感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走
这些资料对于【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴上万个测试工程师们走过最艰难的路程希望也能帮助到你