python-列表理解中的测试和断言
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-列表理解中的测试和断言,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1668字,纯文字阅读大概需要3分钟。
内容图文
![python-列表理解中的测试和断言](/upload/InfoBanner/zyjiaocheng/683/9c5d0f3556854cfe85df9039e87480e6.jpg)
我是python测试的新手,如果可能的话,请使用pytest来检查我的函数是否正确.有输入和预期输出的列表:
test_cases = [
("...Guide: From Mid $1.3ms", [(1300000)]),
("OFFERS OVER $1,100,000", [(1100000)]),
("...Around $1.35million", [(1350000)]),
("Guide above $1.2m", [(1200000)]),
("...From $2.55 Million", [(2550000)]),
("Low $2 millions", [(2000000)]),
("Mid $2M's Buyers", [(2000000)]),
("$305,000 - $349,950", [(305000), (349950)]),
("...$485,000 and $510,000", [(485000), (510000)]),
("...High $300,000's", [(300000)]),
("...000 + to $625,000 +", [(625000)]),
("$299k", [(299000)]),
("... Buyers Guide $1.29M+", [(1290000)]),
("$1m", [(1000000)]),
("$1,000,000.00", [(1000000)])
]
如果给出test_cases [n] [0]作为输入,测试我的函数是否返回test_cases [n] [1]的最优雅方法是什么?我能否以某种方式断言这一点,同时仍然获得有意义的结果(即,每10个测试中有7个成功完成,每10个测试中有10个成功完成)?
解决方法:
The parametrize decorator会这样做.您给它一个输入列表,它将对输入列表的每个元素运行一次经过修饰的测试.每个测试都会作为单独的测试报告.
import pytest
test_cases = [
("...Guide: From Mid $1.3ms", [(1300000)]),
("OFFERS OVER $1,100,000", [(1100000)]),
("...Around $1.35million", [(1350000)]),
("Guide above $1.2m", [(1200000)]),
("...From $2.55 Million", [(2550000)]),
("Low $2 millions", [(2000000)]),
("Mid $2M's Buyers", [(2000000)]),
("$305,000 - $349,950", [(305000), (349950)]),
("...$485,000 and $510,000", [(485000), (510000)]),
("...High $300,000's", [(300000)]),
("...000 + to $625,000 +", [(625000)]),
("$299k", [(299000)]),
("... Buyers Guide $1.29M+", [(1290000)]),
("$1m", [(1000000)]),
("$1,000,000.00", [(1000000)])
]
@pytest.mark.parametrize("in", "out", test_cases)
def test(in, out):
assert f(in) == out
内容总结
以上是互联网集市为您收集整理的python-列表理解中的测试和断言全部内容,希望文章能够帮你解决python-列表理解中的测试和断言所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。