我一直得到一个错误,而试图在PyCharm做一个测试.它一直说没有测试被发现和空套件.我已经尝试修补了一堆不同的东西,似乎不能得到这个想通了.有人知道是什么问题?
import unittest
from city_functions import city_country
class TestCitiesCase(unittest.TestCase):
"""Tests the combined function in city_functions"""
def test_city_country(self):
"""Does seattle united states of america work"""
seattle = city_country('seattle', 'united states of america')
self.assertEqual(seattle, 'seattle, united states of america')
def test_city_country_population(self):
"""Does seattle united states of america population 500000 work?"""
seattle = city_country('seattle', 'united states of america', 500000)
self.assertEqual(seattle, 'seattle, united states of america, population 500000')
unittest.main()
城市功能.py -
def city_country(city, country, population=''):
if population:
city = city.title() + ', ' + country.title() + ', population ' + str(population)
else:
city = city.title() + ', ' + country.title()
return city
1条答案
按热度按时间k4emjkb11#
经历了同样的事情,但是如果你去掉
unittest.main()
,你的测试应该可以正常工作。或有