您的位置:首页 > 编程语言

编写测试代码时候的小错误——takes 0 positional arguments but 1 was given

2017-12-18 16:29 459 查看
import unittest

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的值,致使测试代码在调用这个函数进行断言时,得不到值而出现错误。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐