1 Star 0 Fork 0

test_xielong/testdev

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_add_div.py 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
test_xielong 提交于 4年前 . 提交作业
import allure
import pytest
import yaml
# from pytest_code.calc import Calculator
with open("./data_source/datasource.yaml") as f:
data_source = yaml.safe_load(f)['datas']
add_datas = data_source['add']
print(add_datas)
div_datas = data_source['div']
print(div_datas)
@allure.feature("计算器加法和除法-测试用例")
class TestAddAndDiv:
# def setup_class(self):
# print("开始计算")
# # 实例化计算器类
# self.calc = Calculator()
#
# def teardown_class(self):
# print("计算结束")
@allure.title("测试相加_{a}_{b}_{expect}")
@pytest.mark.parametrize('a,b,expect', add_datas)
def test_add(self, get_calc, a, b, expect):
# 调用 add 方法
result = get_calc.add(a, b)
# 若result1为float型,就保留两位小数
if isinstance(result, float):
result = round(result, 4)
# 加法的断言
assert result == expect
@allure.title("测试相除_{a}_{b}_{expect}")
@pytest.mark.parametrize('a,b,expect', div_datas)
def test_div(self, get_calc, a, b, expect):
if b == 0:
print("分母为零,无法计算")
else:
# 调用 div 方法
result = get_calc.div(a, b)
# 若除数为0,则result记为null
if isinstance(result, float):
result = round(result, 4)
# 除法的断言
assert result == expect
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/test_xielong/testdev.git
git@gitee.com:test_xielong/testdev.git
test_xielong
testdev
testdev
master

搜索帮助