OMSR 发表于 2022-6-24 12:38:43

报错,No module named 'test.cities'

import unittest
from city_functions import city_detail


class CityTestCase(unittest.TestCase):
    """测试city_functions.py."""

    def test_city_detail(self):
      """是否可以处理河南,中国这样的字串"""
      detail = city_detail("santiago", "chile", "500000")
      self.assertEqual(detail, "Santiago, Chile, -500000")


if __name__ == "__main__":
    unittest.main()
def city_detail(city, country, population):
    return f"{city}, {country}, -{population}".title()

运行之后报错Traceback (most recent call last):
File "F:\anaconda3\envs\第11章\lib\unittest\loader.py", line 153, in loadTestsFromName
    module = __import__(module_name)
ModuleNotFoundError: No module named 'test.cities'

报错的位置是系统里的文件,各位大佬,这种情况该怎么办?

OMSR 发表于 2022-6-24 15:12:33

尝试了几遍,发现是title()的问题,第二个代码里想将首字母大写不能最后加一个title(),应该f"{city.title()}, {country.title()}, -{population.title()}"不删贴了,留个纪念

nikezhi 发表于 2022-6-24 15:13:36

OMSR 发表于 2022-6-24 15:12
尝试了几遍,发现是title()的问题,第二个代码里想将首字母大写不能最后加一个title(),应该不删贴了, ...

那就留着纪念吧
页: [1]
查看完整版本: 报错,No module named 'test.cities'