我是靠谱客的博主 含蓄毛豆,这篇文章主要介绍Python3 unittest 发现不了test case,返回no tests were found,现在分享给大家,希望可以做个参考。

学习unittest过程,遇到no tests were found错误,

执行如下示例代码,unittest.main()运行后,代码没有进入到NamesTestCase运行。

import unittest
from NameFunction import get_formatted_name
class NamesTestCase(unittest.TestCase):
def test_first_last_name(self):
formatted_name=get_formatted_name('elsa', 'chen')
self.assertEqual(formatted_name, 'Elsa Chen')
unittest.main()

代码没有进入方法test_first_last_name()中,所以会出现no tests were found的情况

为了让代码行 unittest.main() 让 Python 运行这个文件中的测试,在python 3.x版本中,需要写成如下格式才能支持执行测试用例

if __name__ == '__main__':
unittest.main()

亲自正确

最后

以上就是含蓄毛豆最近收集整理的关于Python3 unittest 发现不了test case,返回no tests were found的全部内容,更多相关Python3内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部