待测文件city_functions.py
def hanshu(city,nation,population=''):
if population:
msg=city.title()+nation.title()+'Population'+str(population)
else:
msg=city.title()+nation.title()
return msg
if __name__=='__main__':
a=hanshu('santiago','chile',5000)
print(a)
测试用例test_cities.py
import unittest
from city_functions import hanshu
class CityTest(unittest.TestCase):
def test_city(self):
testresult=hanshu('santiago','chile',population=5000)
self.assertEqual(testresult,'SantiagoChilePopulation5000')
unittest.main()