• Pytest运行指定的case,这个方法真的很高效……


    Pytest运行指定的case

      在测试工作中,当我们写了较多的cases时,如果每次都要全部运行一遍,无疑是很浪费时间的,而且效率低下。

    但是有一种方法可以帮助你快速地运行指定的测试用例,提高测试效率,那就是使用Pytest来运行指定的case!这种方法不仅可以节省时间,而且能够准确地测试出特定的功能和模块。

    赶紧来试一试,相信你会很快感受到它的高效和便捷!

    例子代码:

    test_aa.py

    1. class TestClassOne(object):
    2.     def test_one(self):
    3.         x = "this"
    4.         assert 't'in x
    5.     def test_two(self):
    6.         x = "hello"
    7.         assert hasattr(x, 'check')
    8. class TestClassTwo(object):
    9.     def test_one(self):
    10.         x = "iphone"
    11.         assert 'p'in x
    12.     def test_two(self):
    13.         x = "apple"
    14.         assert hasattr(x, 'check')

     

    运行模式:

    模式1:直接运行test_aa.py文件中的所有cases:

    pytest test_aa.py

    模式2:运行test_aa.py文件中的TestClassOne这个class下的两个cases:

    pytest test_aa.py::TestClassOne
    模式3:运行test_aa.py文件中的TestClassTwo这个class下的test_one:
    pytest test_aa.py::TestClassTwo::test_one

    注意:定义class时,需要以T开头,不然pytest是不会去运行该class的。

    B站讲的最详细的pytest教程,快速入门精选pytest实战教程!!

    【留言:录播教程,即可免费获取】

  • 相关阅读:
    普中51-数码管实验
    【Python模块】日期时间
    c++类型转换
    Selenium+Pytest自动化测试框架详解
    ipv4 网络划分,网络段与子网掩码
    深入 Java 线程池:从设计思想到源码解读
    精彩回顾 | 云原生系统软件的产业应用
    智能网络安全网卡|这是不是你要的安全感
    Methods and Interfaces Part3
    OpenHarmony实战开发-文件上传下载性能提升指导。
  • 原文地址:https://blog.csdn.net/m0_70618214/article/details/130912377