测试用例代码问题
这是被测试的函数代码块:def get_formatted_name(first, last, middle=''):
"""Generate a neatly formatted full name."""
if middle:
full_name = f"{first} {middle} {last}"
else:
full_name = f"{first} {last}"
return full_name.title()
这是测试用例:
import unittest
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase):
"""Tests for 'name_function.py'."""
def test_first_last_name(self):
"""Do names like 'Janis Joplin' work?"""
formatted_name = get_formatted_name('janis', 'joplin')
self.assertEqual(formatted_name, 'Janis Joplin')
def test_first_last_middle_name(self):
"""Do names like 'Wolfgang Amadeus Mozart' work?"""
formatted_name = get_formatted_name(
'wolfgang', 'mozart', 'amadeus')
self.assertEqual(formatted_name, 'Wolfgang Amadeus Mozart')
if __name__ == '__main__':
unittest.main()
求解最后的“if __name__ == '__main__':
unittest.main()”是什么意思,有什么作用
通俗的讲就是防止本脚本被误调用。
https://www.zhihu.com/question/49136398 suchocolate 发表于 2021-11-22 16:29
通俗的讲就是防止本脚本被误调用。
https://www.zhihu.com/question/49136398
懂了,谢谢
页:
[1]