【发布时间】:2018-06-09 13:54:30
【问题描述】:
我被这个问题困住了,我不知道为什么这个测试不起作用。请任何人帮助我。
下面的代码在 cityname.py 文件中
def get_name(city, country):
return (city.title() + ", " + country.title())
下面的代码在 test_cities.py 文件中
import unittest
from cityname import get_name
class CitiesTestCase(unittest.TestCase):
def test_city_country(self):
santiago_chile = get_name('santiago', 'chile')
self.assertEqual(santiago_chile, 'Santiago, Chile')
unittest.main()
这是输出
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
【问题讨论】:
-
如果您发布的代码中的缩进与文件中的内容匹配,那是因为
test_city_country函数不属于CitiesTestCase,因为没有缩进 -
为我工作。你是如何运行它的?
-
我知道它应该可以工作,但我认为在导入我的文件时可能存在某种问题(?),我不知道如何处理它。我在pycharm中正常运行它,我没有办法运行它。
标签: python unit-testing testing