一开始在windows下运行没有问题,但是在linux下运行却报如下错误:

​ AttributeError: module 'unittest' has no attribute 'TestRunner',

在网上找了好多资料看了一下都提示存在与unittest模块同名的.py文件

但是我查了一点也没有发现与之同名的文件,最后偶然间看到有人用TextTestRunner()这个方法于是把TestRunner换成TextTestRunner问题解决下面是我的代码:

import unittest
from selenium import webdriver
import time class Search_KeyWords(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.url = "http://www.baidu.com/" def test_search_davieyang(self):
driver = self.driver
driver.get(self.url)
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("davieyang")
driver.find_element_by_id("su").click()
time.sleep(3)
try:
self.assertTrue("davieyang" in driver.page_source)
except AssertionError as e:
raise e def test_search_selenium(self):
driver = self.driver
driver.get(self.url)
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
try:
self.assertTrue("davieyang" in driver.page_source)
except AssertionError as e:
raise e def tearDown(self):
self.driver.quit() if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(Search_KeyWords('test_search_davieyang'))
suite.addTest(Search_KeyWords('test_search_selenium'))
runner = unittest.TestRunner()
runner.run(suite)

修改后的代码:

import unittest
from selenium import webdriver
import time class Search_KeyWords(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.url = "http://www.baidu.com/" def test_search_davieyang(self):
driver = self.driver
driver.get(self.url)
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("davieyang")
driver.find_element_by_id("su").click()
time.sleep(3)
try:
self.assertTrue("davieyang" in driver.page_source)
except AssertionError as e:
raise e def test_search_selenium(self):
driver = self.driver
driver.get(self.url)
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
try:
self.assertTrue("davieyang" in driver.page_source)
except AssertionError as e:
raise e def tearDown(self):
self.driver.quit() if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(Search_KeyWords('test_search_davieyang'))
suite.addTest(Search_KeyWords('test_search_selenium'))
runner = unittest.TextTestRunner()
runner.run(suite)

unittest模块在linux报错: AttributeError: module 'unittest' has no attribute 'TestRunner'的更多相关文章

  1. 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'

    一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...

  2. python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'

    python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...

  3. python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?

    python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...

  4. [已解决]pycharm报错:AttributeError: module 'pip' has no attribute 'main'

    > 更新pip后,pycharm更新模块报错,经过一番查找,现提供两种解决办法. 报错片段信息如下: AttributeError: module 'pip' has no attribute ...

  5. Centos6.5下安装jumpserver-1.4.1报错AttributeError: module 'gssapi' has no attribute 'GSSException'

    报错: >>> import paramiko Traceback (most recent call last): File "<stdin>", ...

  6. 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"

    最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...

  7. Pycharm 报错 AttributeError: module 'pip' has no attribute 'main'

    1.打开文件packaging_tool.py: D:\Program files\pycharm\PyCharm 2016.3.2\helpers\packaging_tool.py 2.添加导入: ...

  8. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  9. moviepy应用pyinstaller打包后执行报错AttributeError: module audio/video.fx.all has no attribute fadein、crop

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 在开发moviepy的Python程序使用pyinstaller打包后 ...

随机推荐

  1. Nginx 的过滤模块是干啥用的?

    上一篇文章我写了 Nginx 的 11 个阶段,很多人都说太长了.这是出于文章完整性的考虑的,11 个阶段嘛,一次性说完就完事了.今天这篇文章比较短,看完没问题. 过滤模块的位置 之前我们介绍了 Ng ...

  2. 括号树 noip(csp??) 2019 洛谷 P5658

    洛谷AC通道 本题,题目长,但是实际想起来十分简单. 首先,对于树上的每一个后括号,我们很容易知道,他的贡献值等于上一个后括号的贡献值 + 1.(当然,前提是要有人跟他匹配,毕竟题目中要求了,是不同的 ...

  3. php CURL 发送请求封装

    cURL可以使用URL的语法模拟浏览器来传输数据,因为它是模拟浏览器,因此它同样支持多种协议,FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 ...

  4. Rocket - config - View

    https://mp.weixin.qq.com/s/b5o3s2DgqOz3-iK8FqPeLQ   介绍配置相关的基础类及其继承关系.   参考链接: https://github.com/fre ...

  5. 重装ArchLinux后修改GRUB配置不生效问题的解决

    重装ArchLinux后修改GRUB配置不生效问题的解决 mount指令看一下挂载,或者vim /etc/fstab看一下有没有/boot,看看fstab是不是没写进去.... 我特喵昨天重装完Arc ...

  6. 企业级Python开发大佬利用网络爬虫技术实现自动发送天气预告邮件

    前天小编带大家利用Python网络爬虫采集了天气网的实时信息,今天小编带大家更进一步,将采集到的天气信息直接发送到邮箱,带大家一起嗨~~拓展来说,这个功能放在企业级角度来看,只要我们拥有客户的邮箱,之 ...

  7. LeetCode 74,直击BAT经典面试题

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题43篇文章,我们今天来看一下LeetCode当中的74题,搜索二维矩阵,search 2D Matrix. 这题的 ...

  8. Java实现 LeetCode 43 字符串相乘

    43. 字符串相乘 给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式. 示例 1: 输入: num1 = "2& ...

  9. Java实现 LeetCode 16 最接近的三数之和

    16. 最接近的三数之和 给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和.假定每组输入只存 ...

  10. Java实现指定年份月份的日历表

    输入指定的年份与月份,看这个月的日历表 package Xueying_Liu; import java.util.Scanner; public class rilibiao { public st ...