python-3.x 我一直在PyCharm中得到一个错误,没有找到测试和空套件

8xiog9wr  于 2023-04-13  发布在  Python
关注(0)|答案(1)|浏览(184)

我一直得到一个错误,而试图在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
k4emjkb1

k4emjkb11#

经历了同样的事情,但是如果你去掉unittest.main(),你的测试应该可以正常工作。
或有

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

相关问题