TypeError: 'TestCase' object is not iterable
这个异常呢其实是因为我对list没有足够熟悉
我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable这个错误 呢?

分析:
这个错误的意思是说TestCase这个对象是不可迭代的(注意到了吗,是TestCase,而不是testcase)
看print(testcase)输出的结果:
<TestCase.获取房源状态>
再看看是哪里调用了testcase对象,在runTest(testcase)函数中
使用for i in testcase 循环读出testcase对象当中的内容

首先testcase = runProject("all")会返回一个列表
我原本想是通过这句代码只取前2条数据,我以为这句代码执行后testcase = runProject("all")[2],testcase对象仍然是一个列表,但实际上这样写是只取了testcase列表中下标为2的元素,而不是testcase这个列表前2个元素了
正确的写法应该是这样的
testcase = runProject("all")[:2]
举个小例子说明一下:
for循环迭代一个列表--正常执行
In [2]: a=["a","b",123] In [4]: for i in a:
...: print(i)
...:
a
b
123
for循环迭代a[:2](a[:2]仍然是一个列表对象)--正常执行
In [8]: a[:2]
Out[8]: ['a', 'b']
In [6]: for i in a[:2]:
...: print(i)
...:
a
b
for循环迭代a[2](a[2]表示列表中下标为2的元素,该元素是数字123,该对象是不可迭代的)--报错了TypeError: 'int' object is not iterable
In [9]: a[2]
Out[9]: 123
In [7]: for i in a[2]:
...: print(i)
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-879d94b1fc77> in <module>
----> 1 for i in a[2]:
2 print(i)
3 TypeError: 'int' object is not iterable
顺例复习一下:
python中可以迭代的对象包括:字符串,列表,元组,字典,文件
TypeError: 'TestCase' object is not iterable的更多相关文章
- TypeError: 'ExcelData' object is not iterable
今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterabl ...
- python TypeError: 'NoneType' object is not iterable
list(set(map(lambda tp_id : tp_id if not ('#' in tp_id) and len(tp_id.strip().replace('\n', '')) > ...
- python"TypeError: 'NoneType' object is not iterable"错误解析
尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...
- Python : TypeError: 'int' object is not iterable
用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...
- append导致TypeError: 'NoneType' object is not iterable
a=[1,2,3] a.append(4) a Out[4]: [1, 2, 3, 4] a=a.append(5) print(a) None a =[1,2,3] print(a.append(4 ...
- python框架Scrapy报错TypeError: 'float' object is not iterable解决
原因是:Twisted版本高了. 解决办法: 只要把Twisted库降级到16.6.0即可: pip3 install Twisted== 注:Twisted16..0安装后,会自动卸载高版本的Twi ...
- selenium报错TypeError: 'FirefoxWebElement' object is not iterable
报错原因element少了s定位一组元素的方法与定位单个元素的方法类似,唯一的区别是在单词element后面多了一个s表示复数. 改为 返回结果为
- 'NoneType' object is not iterable
"TypeError: 'NoneType' object is not iterable" 一般是返回值为None同时赋值给了多个变量
- Python问题:'Nonetype' object is not iterable
参考链接:http://blog.csdn.net/dataspark/article/details/9953225 [解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的 ...
随机推荐
- Objective-C 2.0 基础要点归纳
本文的阅读基本条件: 具备C/C++基础知识,了解面向对象特征 阅读过<Objective-C 2.0 程序设计(第二版)>.<Objective-C 程序设计 第6版>或相关 ...
- 利用栈Stack实现队列(Queue)
实现说明: 入队时,将元素压入s1; 出队时,推断s2是否为空,如不为空,则直接弹出顶元素:如为空.则将s1的元素逐个"倒入"s2.把最后一个元素弹出并出队; 这个思路,避免了重复 ...
- karaf增加自己定义log4j的配置
配置文件: karaf_home/etc/org.ops4j.pax.logging.cfg 增加配置: ### direct log messages to stdout ### log4j.app ...
- win32gui.EnumWindows my.os.EnumWindows.py
import win32guidef _MyCallback(hwnd, extra): windows = extra temp = [] temp.append(hex(hwnd)) temp.a ...
- LAMP安装问题【已解决】
1.编译不通过提示cannot find mysql header files under /usr/local/mysql解决办法:修改./configuer --with-mysql=/usr/ ...
- go 安装方法
wget https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1. ...
- 【USACO 2010FEB】 slowdown
[题目链接] 点击打开链接 [算法] dfs序 + 线段树 树链剖分同样可以解决这个问题 [代码] #include<bits/stdc++.h> using namespace std; ...
- Hadoop 分布式环境slave节点重启忽然不好使了
Hadoop 分布式环境slaves节点重启: 忽然无法启动DataNode和NodeManager处理: 在master节点: vim /etc/hosts: 修改slave 节点的IP (这个时候 ...
- 盘点国内网站常用的一些 CDN 公共库加速服务(转载)
百度CND jQuery 地址:<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></scri ...
- CodeForces 382C Arithmetic Progression (排序+分类讨论)
题意:给出一个长度为n的序列,表示有n张卡片,上面的数字,现在还有一张卡片,上面没有数字,问说可以写几种数字在这张卡片上面, 使得n+1张卡片上的数字可以排列成一个等差数列,有无限多种时输出-1. 析 ...