import unittest
from city_functions import get_city_country
from city_functions import get_city_country
class CityFuctionTestCase(unittest.TestCase):
def test_city_country_population():
city_country_population=get_city_country('santiago','chile',5000000)self.assertEqual(city_country_population,'Santiago,Chile,population=5000000')
以上是我编写的一个测试代码,然而出现了takes 0 positional arguments but 1 was given。其根本原因是我没有在类中的函数内引入self,即标红处应该改成
def test_city_country_population(self):
这是一个很基本的,但是很严重的错误。只是因为测试类中无需写__init__()函数,所以就连self都忘记了。。。。
==============================================================================================================
在编写测试代码时候,会出现属性错误。我的问题是,在编写的被测试代码中,某个函数没有给出return的值,致使测试代码在调用这个函数进行断言时,得不到值而出现错误。