20221016 Python Pytest 实战训练营

PPT

代码地址

学习路线

pytest 学习路线.xmind.zip (73.3 KB)

课后调查

https://jinshuju.net/f/tLKDzb

pycharm pytest设置

练习一

测试用例

计算器测试用例.xlsx (14.0 KB)

练习提交

  • 可以回复gitee链接地址
  • 也可以回复代码

练习二

  • 使用参数化实现测试数据的动态传递
  • 所有用例执行完成,完成日志打印

日志配置:python 输出日志配置

from question import Calculator
import pytest
class Testcaculator(Calculator):
    def test_001(self):
        result=self.add(1,1)
        expect=2
        assert result==expect
    def test_002(self):
        result=self.add(-0.01,0.02)
        expect=0.01
        assert result==expect
    def test_003(self):
        result=self.add(10,0.02)
        expect=10.02
        assert result==expect
    def test_004(self):
        result=self.add(98.99,99)
        expect=197.99
        assert result==expect
    def test_005(self):
        result=self.add(99,98.99)
        expect=197.99
        assert result==expect
    def test_006(self):
        result=self.add(-99,-98.99)
        expect=-197.99
        assert result==expect
    def test_007(self):
        result=self.add(-98.99,-99)
        expect=-197.99
        assert result==expect
    def test_008(self):
        result=self.add(99.01,0)
        expect='参数大小超出范围'
        assert result==expect
    def test_009(self):
        result=self.add(-99.01,-1)
        expect='参数大小超出范围'
        assert result==expect
    def test_010(self):
        result=self.add(2,99.01)
        expect='参数大小超出范围'
        assert result==expect
    def test_011(self):
        result=self.add(1,-99.01)
        expect='参数大小超出范围'
        assert result==expect
    def test_012(self):
        result=self.add('文',9.3)
        expect='参数大小超出范围'
        assert result==expect
    def test_013(self):
        result=self.add(4,'文')
        expect='参数大小超出范围'
        assert result==expect


class TestAdd:
    def test_add1(self):
        # 调用calculator.py 中的add()方法
        # 实例化一个Calculator()实例
        calc = Calculator()
        # 实际 结点
        result = calc.add(1, 1)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = 2
        # 断言
        assert result == expect

    def test_add2(self):
        calc = Calculator()
        result = calc.add(-0.01, 0.02)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = 0.01
        # 断言
        assert result == expect

    def test_add3(self):
        calc = Calculator()
        result = calc.add(10, 0.02)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = 10.02
        # 断言
        assert result == expect

    def test_add4(self):
        calc = Calculator()
        result = calc.add(98.99, 99)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = 197.99
        # 断言
        assert result == expect
    def test_add5(self):
        calc = Calculator()
        result = calc.add(-98.99, -99)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = -197.99
        # 断言
        assert result == expect
    def test_add6(self):
        calc = Calculator()
        result = calc.add(-99, -98.99)
        print(f"实际结果为:{result}")
        # 期望结果
        expect =-197.99
        # 断言
        assert result == expect

    def test_add7(self):
        calc = Calculator()
        result = calc.add(99.01, 0)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = "参数大小超出范围"
        # 断言
        assert result == expect
    def test_add8(self):
        calc = Calculator()
        result = calc.add(-99.01, -1)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = "参数大小超出范围"
        # 断言
        assert result == expect


1 个赞
class Base:
    def setup(self):
        print('计算开始')
        self.calculator = Calculator()
        

    def teardown(self):
        logger.info("计算结束")

    def teardown_class(self):
        print('结束测试')
import pytest
import allure

from test1.cases.base.base import Base


@allure.feature('加法运算')
class TestCalculator(Base):

    @allure.story('加法运算的P0用例')
    @pytest.mark.parametrize('x,y,excepted', [(1, 1, 2), (-0.01, 0.02, 0.01), (10, 0.02, 10.02)])
    def test_add_p0(self, x, y, excepted):
        with allure.step('调用加法函数'):
            result = self.calculator.add(x, y)
            allure.attach.file(r'D:\2022-05-03 214439.png', name='屏幕截图',
                               attachment_type=allure.attachment_type.JPG,extension='.jpg')
            print(result)
        with allure.step('断言'):
            allure.attach('这是一个文本格式')
            assert self.calculator.add(x, y) == excepted

    @allure.story('加法运算的P1用例')
    @pytest.mark.parametrize('x,y,excepted',
                             [(98.99, 99, 197.99), (99, 98.99, 197.99), (-98.99, -99, -197.99), (-99, -98.99, -197.99)])
    def test_add_p1(self, x, y, excepted):
        assert self.calculator.add(x, y) == excepted

    @allure.story('加法运算的反向用例')
    @pytest.mark.parametrize('x,y,excepted', [(99.01, 0, '参数大小超出范围')])
    def test_add_p2(self, x, y, excepted):
        assert self.calculator.add(x, y) == excepted

1 个赞
class TestAdd:
    def test_add1(self):
        # 调用calculator.py 中的add()方法
        # 实例化一个Calculator()实例
        calc = Calculator()
        # 实际 结点
        result = calc.add(1,1)
        print(f"实际结果为:{result}")
        # 期望结果
        expect = 2
        # 断言
        assert result == expect
    def test_add2(self):
        calc = Calculator()
        result = calc.add(-0.01,0.02)
        expect = 0.01
        assert result == expect
    def test_add3(self):
        calc = Calculator()
        result = calc.add(10,0.02)
        expect = 10.02
        assert result == expect
    def test_add4(self):
        calc = Calculator()
        result = calc.add(98.99,99)
        expect = 197.99
        assert result == expect
    def test_add5(self):
        calc = Calculator()
        result = calc.add(99,98.99)
        expect = 197.99
        assert result == expect

    def test_add6(self):
        calc = Calculator()
        result = calc.add(-98.99, -99)
        expect = -197.99
        assert result == expect
    def test_add7(self):
        calc = Calculator()
        result = calc.add(-99,-98.99)
        expect = -197.99
        assert result == expect
    def test_add8(self):
        calc = Calculator()
        result = calc.add(99.01,0)
        expect = '展示提示信息'
        assert result == expect
    def test_add9(self):
        calc = Calculator()
        result = calc.add(-99.01,-1)
        expect = '展示提示信息'
        assert result == expect
    def test_add10(self):
        calc = Calculator()
        result = calc.add(2,99.01)
        expect = '展示提示信息'
        assert result == expect
    def test_add11(self):
        calc = Calculator()
        result = calc.add(1,-99.01)
        expect = '展示提示信息'
        assert result == expect
    def test_add12(self):
        calc = Calculator()
        result = calc.add('文',9.3)
        expect = '展示提示信息'
        assert result == expect
    def test_add13(self):
        calc = Calculator()
        result = calc.add(4,'字')
        expect = '展示提示信息'
        assert result == expect


from CalculatorProject.script.calculator import Calculator
    
    
    class TestAdd:
        def test_add1(self):
            # 调用calculator.py 中的add()方法
            # 实例化一个Calculator()实例
            calc = Calculator()
            # 实际 结点
            result = calc.add(1, 1)
            print(f"实际结果为:{result}")
            # 期望结果
            expect = 2
            # 断言
            assert result == expect
    
        def test_add2(self):
            calc = Calculator()
            result = calc.add(-0.01, 0.02)
            print(f"实际结果为:{result}")
            expect = 0.01
            assert result == expect
    
        def test_add3(self):
            calc = Calculator()
            result = calc.add(10, 0.02)
            print(f"实际结果为:{result}")
            expect = 10.02
            assert result == expect
    
        def test_add4(self):
            calc = Calculator()
            result = calc.add(98.99, 99)
            print(f"实际结果为:{result}")
            expect = 197.99
            assert result == expect
    
        def test_add5(self):
            calc = Calculator()
            result = calc.add(99, 98.99)
            print(f"实际结果为:{result}")
            expect = 197.99
            assert result == expect
    
        def test_add6(self):
            calc = Calculator()
            result = calc.add(-98.99, -99)
            print(f"实际结果为:{result}")
            expect = -197.99
            assert result == expect
    
        def test_add7(self):
            calc = Calculator()
            result = calc.add(-99, -98.99)
            print(f"实际结果为:{result}")
            expect = -197.99
            assert result == expect
    
        def test_add8(self):
            calc = Calculator()
            result = calc.add(98.99, 99)
            print(f"实际结果为:{result}")
            expect = 197.99
            assert result == expect
    
        def test_add9(self):
            calc = Calculator()
            result = calc.add(99.01, 0)
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect
    
        def test_add10(self):
            calc = Calculator()
            result = calc.add(-99.01, -1)
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect
    
        def test_add11(self):
            calc = Calculator()
            result = calc.add(2, 99.01)
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect
    
        def test_add12(self):
            calc = Calculator()
            result = calc.add(1, -99.01)
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect
    
        def test_add13(self):
            calc = Calculator()
            result = calc.add(1, -99.01)
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect
    
        def test_add14(self):
            calc = Calculator()
            result = calc.add("文", 9.3)
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect
    
        def test_add15(self):
            calc = Calculator()
            result = calc.add(4, "字")
            print(f"实际结果为:{result}")
            expect = "参数大小超出范围"
            assert result == expect

  • 去测试一个方法,不是继承它,是实例化那个类,再去使用实例化的对象调用里面的方法
from CalculatorProject.script.calculator import Calculator


class TestAdd:
    # 实例化一个Calculator()实例
    calc = Calculator()

    def setup(self):
        print("开始计算")

    def teardown(self):
        print("结束计算")

    def test_add_001(self):
        # 调用calculator.py 中的add()方法
        # 实际 结点
        result = self.calc.add(1, 1)
        # 期望结果
        expect = 2
        # 断言
        assert result == expect

    def test_add_002(self):
        result = self.calc.add(-0.01, 0.02)
        expect = 0.01
        assert expect == result

    def test_add_003(self):
        result = self.calc.add(10, 0.02)
        expect = 10.02
        assert expect == result

    def test_add_004(self):
        result = self.calc.add(98.99, 99)
        expect = 197.99
        assert expect == result

    def test_add_005(self):
        result = self.calc.add(99, 98.99)
        expect = 197.99
        assert expect == result

    def test_add_006(self):
        result = self.calc.add(-98.99, -99)
        expect = -197.99
        assert expect == result

    def test_add_007(self):
        result = self.calc.add(-99, -98.99)
        expect = -197.99
        assert expect == result

    def test_add_008(self):
        result = self.calc.add(99.01, -1)
        expect = "参数大小超出范围"
        assert expect == result

    def test_add_009(self):
        result = self.calc.add(-99.01, 0)
        expect = "参数大小超出范围"
        assert expect == result

    def test_add_010(self):
        result = self.calc.add(2, 99.01)
        expect = "参数大小超出范围"
        assert expect == result

    def test_add_011(self):
        result = self.calc.add(1, -99.01)
        expect = "参数大小超出范围"
        assert expect == result

    def test_add_012(self):
        result = self.calc.add("加法", 9.3)
        expect = "参数大小超出范围"
        assert expect == result

    def test_add_013(self):
        result = self.calc.add(4, "加法")
        expect = "参数大小超出范围"
        assert expect == result

  • “展示提示信息” 需要改成对应的信息内容

Base.py

from CalculatorProject.script.calculator import Calculator
import logging


class Base:
    def setup_class(self):
        self.calc = Calculator()

    def setup_method(self):
        logging.info("=====开始计算=====")

    def teardown_method(self):
        logging.info("=====结束计算=====")

    def teardown_class(self):
        logging.info("=====结束测试=====")

test_add.py

import pytest

from CalculatorProject.test.base.Base import Base
import logging


class TestAdd(Base):

    @pytest.mark.parametrize('a,b,res',
                             [(1, 1, 2), (-0.01, 0.02, 0.01), (10, 0.02, 0.01)
                              ])
    @pytest.mark.p0
    def test_add1(self, a, b, res):
        try:
            # 调用calculator.py 中的add()方法
            result = self.calc.add(a, b)
        except TypeError as e:
            logging.info(f"输入类型为字符串,类型错误:{e}")
        # 断言
        assert result == res

    @pytest.mark.parametrize('a,b,res', [(98.99, 99, 197.99),
                                         (99, 98.99, 197.99),
                                         (-98.99, -99, -197.99),
                                         (-99, -98.99, -197.99),
                                         (99.01, 0, '参数大小超出范围'),
                                         (-99.01, -1, '参数大小超出范围'),
                                         (2, 99.01, '参数大小超出范围'),
                                         ('文', 9.3, '参数大小超出范围'),
                                         (4, '字', '参数大小超出范围'),
                                         ('nu', 0.2, '参数大小超出范围'),
                                         (30, 't', '参数大小超出范围'),
                                         ('*&', 0.2, '参数大小超出范围'),
                                         (21.45, '@', '参数大小超出范围'), ])
    @pytest.mark.p1
    def test_add_p1(self, a, b, res):
        try:
            # 调用calculator.py 中的add()方法
            result = self.calc.add(a, b)
        except TypeError as e:
            logging.info(f"输入类型为字符串,类型错误:{e}")
        # 断言
        assert result == res

    @pytest.mark.parametrize('a,b,res',
                             [('', 20.93, '参数大小超出范围'),
                              (-3, '', '参数大小超出范围'),
                              (' ', 3.14, '参数大小超出范围'),
                              (-90, ' ', '参数大小超出范围')])
    @pytest.mark.p2
    def test_add_p2(self, a, b, res):
        try:
            # 调用calculator.py 中的add()方法
            result = self.calc.add(a, b)
        except TypeError as e:
            logging.info(f"输入类型为字符串,类型错误:{e}")
        # 断言
        assert result == res


if __name__ == '__main__':
    pytest.main(['-sv'])

log_util.py

import logging
import os

from logging.handlers import RotatingFileHandler

# 绑定绑定句柄到logger对象
logger = logging.getLogger(__name__)
# 获取当前工具文件所在的路径
root_path = os.path.dirname(os.path.abspath(__file__))
# 拼接当前要输出日志的路径
log_dir_path = os.sep.join([root_path, f'/logs'])
if not os.path.isdir(log_dir_path):
    os.mkdir(log_dir_path)
# 创建日志记录器,指明日志保存路径,每个日志的大小,保存日志的上限
file_log_handler = RotatingFileHandler(os.sep.join([log_dir_path, 'log.log']),
                                       maxBytes=1024 * 1024, backupCount=10)
# 设置日志的格式
date_string = '%Y-%m-%d %H:%M:%S'
formatter = logging.Formatter(
    '[%(asctime)s] [%(levelname)s] [%(filename)s]/[line: %(lineno)d]/[%(funcName)s] %(message)s ',
    date_string)
# 日志输出到控制台的句柄
stream_handler = logging.StreamHandler()
# 将日志记录器指定日志的格式
file_log_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)
# 为全局的日志工具对象添加日志记录器
# 绑定绑定句柄到logger对象
logger.addHandler(stream_handler)
logger.addHandler(file_log_handler)
# 设置日志输出级别
logger.setLevel(level=logging.INFO)

1 个赞
import logging
import os
from logging.handlers import RotatingFileHandler

import pytest

from CalculatorProject.script.calculator import Calculator


class Logging():
    # 绑定绑定句柄到logger对象
    logger = logging.getLogger(__name__)
    # 获取当前工具文件所在的路径
    root_path = os.path.dirname(os.path.abspath(__file__))
    # 拼接当前要输出日志的路径
    log_dir_path = os.sep.join([root_path, f'/logs'])
    if not os.path.isdir(log_dir_path):
        os.mkdir(log_dir_path)
    # 创建日志记录器,指明日志保存路径,每个日志的大小,保存日志的上限
    file_log_handler = RotatingFileHandler(os.sep.join([log_dir_path, 'log.log']), maxBytes=1024 * 1024, backupCount=10)
    # 设置日志的格式
    date_string = '%Y-%m-%d %H:%M:%S'
    formatter = logging.Formatter(
        '[%(asctime)s] [%(levelname)s] [%(filename)s]/[line: %(lineno)d]/[%(funcName)s] %(message)s ', date_string)
    # 日志输出到控制台的句柄
    stream_handler = logging.StreamHandler()
    # 将日志记录器指定日志的格式
    file_log_handler.setFormatter(formatter)
    stream_handler.setFormatter(formatter)
    # 为全局的日志工具对象添加日志记录器
    # 绑定绑定句柄到logger对象
    logger.addHandler(stream_handler)
    logger.addHandler(file_log_handler)
    # 设置日志输出级别
    logger.setLevel(level=logging.INFO)

class TestAdd:
    # 实例化一个Calculator()实例
    calc = Calculator()

    def setup(self):
        print("开始计算")

    def teardown(self):
        print("结束计算")

    def teardown_class(self):
        print("退出计算")

    @pytest.mark.addP0
    @pytest.mark.parametrize("x,y,excepted", [[1, 1, 2], [-0.01, 0.02, 0.01], [10, 0.02, 10.02]])
    def test_add_001(self, x, y, excepted):
        result = self.calc.add(x, y)
        logging.info(f"结果为{result}")
        assert result == excepted

    @pytest.mark.addP1Ture
    @pytest.mark.parametrize("x,y,excepted", [[98.99, 99, 197.99], [99, 98.99, 0197.99], [-98.99, -99, -197.99],
                                              [-99, -98.99, -197.99]])
    def test_add_002(self, x, y, excepted):
        result = self.calc.add(x, y)
        logging.info(f"结果为{result}")
        assert result == excepted

    @pytest.mark.addP1Falsea
    @pytest.mark.parametrize("x,y,excepted", [[99.01, 0, "参数大小超出范围"], [-99.01, -1, "参数大小超出范围"],
                                              [2, 99.01, "参数大小超出范围"], [1, -99.01, "参数大小超出范围"]],ids=["add_008","add_009","add_0010","add_0011"])
    def test_add_003(self, x, y, excepted):
        result = self.calc.add(x, y)
        logging.info(f"结果为{result}")
        assert result == excepted

    @pytest.mark.addP1False2
    @pytest.mark.parametrize("x,y,excepted", [["加", 0, "参数大小超出范围"], [-99.01, "加", "参数大小超出范围"]])
    def test_add_004(self, x, y, excepted):
        try:
            result = self.calc.add(x, y)
        except TypeError as e:
            logging.info(f"类型错误{e}")

import allure
import pytest

from CalculatorProject.Script.calculator import Calculator
from CalculatorProject.test.cases.bases import Base
from CalculatorProject.test.cases.log_util import logger


@allure.feature('加法功能')
class Testcase(Base):

    @allure.story("正向用例")
    @pytest.mark.P0
    @pytest.mark.parametrize('x,y,excepted', [(1, 1, 2), (-0.01, 0.02, 0.01), (10, 0.02, 10.02)])
    def test_add_001(self, x, y, excepted):
        logger.info('实际结果=预期结果')
        assert self.calculator.add(x, y) == excepted

    @allure.story("有效边界")
    @pytest.mark.P1
    @pytest.mark.parametrize('x,y,excepted',
                             [(98.99, 99, 197.99), (99, 98.99, 197.99), (-98.99, -99, -197.99), (-99, -98.99, -197.99)])
    def test_add_002(self, x, y, excepted):
        logger.info('实际结果=预期结果')
        assert self.calculator.add(x, y) == excepted

    @allure.story("无效边界")
    @pytest.mark.P1
    @pytest.mark.parametrize('x,y,excepted',
                             [(99.01, 0, '参数大小超出范围'), (-99.01, -1, '参数大小超出范围'), (2, 99.01, '参数大小超出范围'),
                              (1, -99.01, '参数大小超出范围')])
    def test_add_003(self, x, y, excepted):
        logger.info('实际结果=预期结果')
        assert self.calculator.add(x, y) == excepted

    @pytest.mark.parametrize('x,y,excepted', [('文',9.3,'参数大小超出范围')])
    def test_add_004(self, x, y, excepted):
        logger.info('异常处理')
        try:
            result=self.calculator.add(x, y)
        except TypeError as e:
            print(f"输入类型为字符串,类型错误:{e}")


1 个赞
#补交作业
import pytest

from CalculatorProject.script.calculator import Calculator
from CalculatorProject.test.base.Base import Base
from CalculatorProject.test.utils.logger import logger


class TestAdd(Base):
    c=[[1,1,2],
    [-0.01, 0.02,0.01],
    [10, 0.02,10.02]]
    @pytest.mark.add
    @pytest.mark.P0
    @pytest.mark.parametrize("a,b,expect", c,ids=["1","2","3"])
    # 参数化的每一个测试数据,都对应的是单独的一条用例 def test_name()
    # 在执行每一条测试数据之前都会调用setup(),执行之后都会调用teardown()
    def test_add1(self,a,b,expect):
        logger.info(f"a={a}, b= {b}, expect={expect}")
        result = self.calc.add(a, b)
        logger.info(f"实际结果为:{result}")
        # 断言
        assert result == expect


    c=[
       (98.99, 99,197.99),
       (99, 98.99,197.99),
       (-98.99, -99,-197.99),
       (-99, -98.99,-197.99),
       (99.01, 0,"参数大小超出范围"),
       (-99.01, -1,"参数大小超出范围"),
       (2, 99.01,"参数大小超出范围"),
       (1, -99.01,"参数大小超出范围"),
       ]
    @pytest.mark.add
    @pytest.mark.P1
    @pytest.mark.parametrize("a,b,expect",c,ids=["1","2","3","4","5","6","7","8"])
    def test_add2(self,a,b,expect):
        logger.info(f"a={a}, b= {b}, expect={expect}")
        result = self.calc.add(a, b)
        logger.info(f"实际结果为:{result}")
        # 断言
        assert result == expect


    @pytest.mark.add
    @pytest.mark.P1
    def test_add12(self):
        try:
            result = self.calc.add("文", 9.3)
        except TypeError as e:
            logger.info(f"输入类型为中文,类型错误:{e}")

    @pytest.mark.add
    @pytest.mark.P1
    def test_add13(self):
        # 异常处理两种方式
        # try:
        #     result = self.calc.add(4, "字")
        # except TypeError as e:
        #     print(f"输入类型为中文,类型错误:{e}")

        with pytest.raises(TypeError) as e:
            result = self.calc.add(4, "字")
        logger.info(f"类型错误:{e}")
        assert e.type == TypeError

import allure
import pytest
import allure
from CalculatorProject.script.calculator import Calculator

@allure.feature("计算器加法运算")
class TestAdd:
    def setup_class(self):
        self.calc = Calculator()
    def teardown_class(self):
        print("结束测试")
    def setup_method(self):
        print("开始计算")
    def teardown_method(self):
        print("结束计算")
    @pytest.mark.add
    @allure.severity(allure.severity_level.BLOCKER)
    def test_add1(self):
        result = self.calc.add(1,1)
        expect = 2
        assert result == expect

    @pytest.mark.add
    @allure.severity(allure.severity_level.BLOCKER)
    def test_add2(self):
        result = self.calc.add(-0.01, 0.02)
        expect = 0.01
        assert result == expect
    @pytest.mark.add
    @allure.severity(allure.severity_level.BLOCKER)
    def test_add3(self):
        result = self.calc.add(10, 0.02)
        expect = 10.02
        assert result == expect
    @pytest.mark.validladd
    @allure.story("有效边界值计算")
    def test_add4(self):
        result = self.calc.add(98.99, 99)
        expect = 197.99
        assert result == expect
    @pytest.mark.validladd
    @allure.story("有效边界值计算")
    def test_add5(self):
        result = self.calc.add(99, 98.99)
        expect = 197.99
        assert result == expect

    @pytest.mark.validladd
    @allure.story("有效边界值计算")
    def test_add6(self):
        result = self.calc.add(-98.99,-99)
        expect = -197.99
        assert result == expect

    @pytest.mark.validladd
    @allure.story("有效边界值计算")
    def test_add7(self):
        result = self.calc.add(-99, -98.99)
        expect = -197.99
        assert result == expect

    @pytest.mark.invalidadd
    @allure.story("无效边界值计算")
    def test_add8(self):
        result = self.calc.add(99.01, 0)
        expect = "参数大小超出范围"
        assert result == expect

    @pytest.mark.invalidadd
    @allure.story("无效边界值计算")
    def test_add9(self):
        result = self.calc.add(-99.01, -1)
        expect = "参数大小超出范围"
        assert result == expect

    @pytest.mark.invalidadd
    @allure.story("无效边界值计算")
    def test_add10(self):
        result = self.calc.add(2,99.01)
        expect = "参数大小超出范围"
        assert result == expect

    @pytest.mark.invalidadd
    @allure.story("无效边界值计算")
    def test_add11(self):
        result = self.calc.add(1,-99.01)
        expect = "参数大小超出范围"
        assert result == expect

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add12(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add('问', "9.4")
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add13(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add('4', "字")
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add14(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add('nu', 0.2)
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add15(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add(30, 't')
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add16(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add('*&', 0.2)
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add17(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add(21.45, '@')
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add18(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add('', 20.93)
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add19(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add(-3, '')
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add20(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add(' ', 3.14)
        print(f"{e}")
        assert e.type == TypeError

    @pytest.mark.errortype
    @allure.story("数据类型不对计算")
    def test_add21(self):
        with pytest.raises(TypeError) as e:
            result = self.calc.add(-90, ' ')
        print(f"{e}")
        assert e.type == TypeError