编写测试代码时候的小错误——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的值,致使测试代码在调用这个函数进行断言时,得不到值而出现错误。
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的值,致使测试代码在调用这个函数进行断言时,得不到值而出现错误。
相关文章推荐
- Python 错误之函数takes 0 positional arguments but 1 was given
- Python-类-函数参数-takes 0 positional arguments but 1 was given
- python3中遇到的一个bug TypeError: is_empty() takes 0 positional arguments but 1 was given
- flask函数已定义参数却出现takes 0 positional arguments but 1 was given的问题
- main() takes 0 positional arguments but 1 was given
- takes 0 positional arguments but 1 was given
- Python:sql_for_inline_foreign_key_references() takes 4 positional arguments but 5 were given
- android:视频录制编写代码一直报非法状态错误,很多时候定位在setVideoEncoder和setAudioEncoder
- takes 3 positional arguments but 4 were given错误
- 编写html表格输出的时候有时候会出现同一列连续出现两行或者是三行的数据内容一样,并且我们想将这些行合并起来,这个时候我们就需要以下这些代码
- 4.2 用 FSI 编写和测试代码
- 安装的db2 v8.1自带的db2驱动用不起,写个jsp页面,用forName()装载测试连接的时候老是出现"no suitable driver“的错误提示
- TypeError in Threading. function takes 1 positional argument but 100 were given
- 读书笔记-编写可测试的 JavaScript 代码-第二章?
- 编写类库时如何添加注释,使得在使用类库的时候有相应的代码提示
- 一起谈.NET技术,VS2010 测试功能之旅:编码的UI测试(4)-通过编写测试代码的方式建立UI测试(下)
- VS2010 测试功能之旅:编码的UI测试(4)-通“.NET研究”过编写测试代码的方式建立UI测试(上)
- 字符设备驱动模块与测试代码编写(转)
- 还为代码编写愁吗?代码生成器将让你编写代码测试代码速度极大提升
- 通过读取excel数据和mysql数据库数据做对比(二)-代码编写测试