pytest学习过程-day01

unittest 的一种单元测试框架,是 Python官方维护 自带的,兼容性比价好测试框架类似,
但是pytest框架使用起来更简洁,效率更高。 首先把unittest编写用例方法流程罗列

# ---------------------unittest编写用例----------------------------------------
# 用例文件:test开头
# 用例类:继承unittest.TestCase
# 用例方法:test开头
# 用例只能使用类去定义

# import unittest
# class TestLogin(unittest.TestCase):
#
#     def test_01(self):
#         assert 1 == 100
#
#     def test_02(self):
#         assert 100 == 100
#
#     def test_03(self):
#         assert 100 == 100
pyest编写用例  罗列
# ---------------------pyest编写用例----------------------------------------
"""
# 默认的用例规范
1、用例文件:test开头
2、以test开头的函数会当成一条测试用例
3、以Test开头的类,会当成测试用例类
    测试类中,以test开头的方法,会当成一条用例

# 注意点:用例规范可以自己通过pytest.ini去配置

"""


新增

# ---------------------pyest用例的前后置---------------------------------------
"""
测试类的前后置方法
    1、用例级别的:setup 和teardown
    2、测试类级别的前后置方法:setup_class 和teardown_class
"""

import pytest

pytest.main(['-s','-v'])
class TestLogin:

    @classmethod
    def setup_class(cls):
        print('----------类级别前置---------------')
        # 用例的前置方法

    @classmethod
    def teardown_class(cls):  # tearDownClass
        print('----------类级别后置---------------')

    def setup(self):  # setUp
        print('----------用例级别前置---------------')
        # 用例的前置方法

    def teardown(self):  # tearDown
        print('----------用例级别后置---------------')

    def test_c01(self):
        print('------case01-------------')
        assert 1000 == 1000

    def test_c03(self):
        print('------case02-------------')
        assert 1000 == 1000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值