#city_function
def name(city,country):
str = city + " " + country
return str.title()
#main
import unittest
from city_functions import name
class NameTestCase(unittest.TestCase):
def test_name(self):
for_name = name('xiao','li')
self.assertEqual(for_name,'Xiao Li')
unittest.main()
结果

本文介绍了Python中定义函数的实例`defname()`,它将城市和国家组合成标题格式。接着展示了如何使用unittest进行单元测试,确保`name()`函数的正确性。测试用例通过了对于'XiaoLi'的预期输出。
621





