加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

pytest---参数化

发布时间:2020-12-14 00:24:03 所属栏目:Linux 来源:网络整理
导读:import pytest @pytest.mark.parametrize(‘test_input,expected‘,[(‘3+5‘,8), (‘2-1‘,1),(‘7*5‘,30)]) def test_eval(test_input,expected): assert eval(test_input)==expected ----eval把字符串转换成表达式 est_param.py::test_eval[2-1-1] test_
import pytest


@pytest.mark.parametrize(‘test_input,expected‘,[(‘3+5‘,8),
(‘2-1‘,1),(‘7*5‘,30)])
def test_eval(test_input,expected):
assert eval(test_input)==expected    ----eval把字符串转换成表达式


est_param.py::test_eval[2-1-1]
test_param.py::test_eval[7*5-30] PASSED [ 33%]PASSED [ 66%]FAILED [100%]
test_param.py:3 (test_eval[7*5-30])
35 != 30

Expected :30
Actual :35
<Click to see difference>

test_input = ‘7*5‘,expected = 30

@pytest.mark.parametrize(‘test_input,
(‘2-1‘,30)])
def test_eval(test_input,expected):
> assert eval(test_input)==expected
E assert 35 == 30          ----提示把30改成35

test_param.py:7: AssertionError

Assertion failed

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读