
一句话来说下,unittest和pytest脚本在pycharm中使用基本是一样的。基本是两种:


“运行(U)pytest in xx.py”的字样


test_a下新建一个脚本test_u.py,脚本如下:# -*- coding:utf-8 -*-
# 作者:NoamaNelson
# 日期:2021/9/3 17:13
# 文件名称:test_u.py
# 作用:xxx
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import unittest
class TestU(unittest.TestCase):
def test_one(self):
money = 1000000
if money > 10000:
print(f"你已经拥有了{money}块钱,已经很富裕了!")
if __name__ == "__main__":
unittest.main()if __name__ == "__main__":上右键,以pytest运行,发现是可以运行的,如下:test_u.py::TestU::test_one PASSED [100%]你已经拥有了1000000块钱,已经很富裕了!
============================== 1 passed in 0.02s ==============================“运行(U)unittests in xx.py”的字样

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。