pytest


```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/7/4 2:32 上午
# @Author  : Wayne
# @Email   : wayne.com
# @File    : test_1.py
# @Software: PyCharm
#pytest使用练习
# from time import sleep
#
# while 1 > 0:
#     print('1234567')
#     sleep(1)
#



import pytest
import allure
class TestClass:

    # @allure.step('步骤1:setup_class')
    def setup_class(self):
        print("setup_class:类中所有用例执行之前")

    def teardown_class(self):
        print("teardown_class:类中所有用例执行之前")

    def setup_method(self):
        print("setup_method:  每个用例开始前执行")

    def teardown_method(self):
        print("teardown_method:  每个用例结束后执行")

    def setup(self):
        print("setup: 每个用例开始前执行")

    def teardown(self):
        print("teardown: 每个用例结束后执行")

    # @allure.step('用例1:用例1')
    def test_one(self):
        '''这是第一个用例 这是用例描述'''
        raise AssertionError('这是错误信息')

    # @allure.step('用例2:用例2')
    def test_two(self):
        '''这是第二个用例 这是用例描述'''
        print("执行第二个用例")


def setup_module():
    print("setup_module:整个.py模块只执行一次")


def teardown_module():
    print("teardown_module:整个.py模块只执行一次")


def setup_function():
    print("setup_function:每个方法用例开始前都会执行")


def teardown_function():
    print("teardown_function:每个方法用例结束前都会执行")


def test_three():
    print("执行第三个用例")


# '''
# 单独执行pytest:pytest -s test_1.py
# 执行pytest并生成Allure报告,python环境中需要安装allure-pytest插件:pytest -s test_1.py --alluredir ./report/allure_raw
# 生成的allure报告的json文件启动服务打开报告:电脑上需要安装allure--》brew install allure:启动allure服务:allure serve report/allure_raw
#
# '''

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值