unittest模块在linux报错: AttributeError: module 'unittest' has no attribute 'TestRunner'
一开始在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'的更多相关文章
- 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'
一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- [已解决]pycharm报错:AttributeError: module 'pip' has no attribute 'main'
> 更新pip后,pycharm更新模块报错,经过一番查找,现提供两种解决办法. 报错片段信息如下: AttributeError: module 'pip' has no attribute ...
- Centos6.5下安装jumpserver-1.4.1报错AttributeError: module 'gssapi' has no attribute 'GSSException'
报错: >>> import paramiko Traceback (most recent call last): File "<stdin>", ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- 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.添加导入: ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- moviepy应用pyinstaller打包后执行报错AttributeError: module audio/video.fx.all has no attribute fadein、crop
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 在开发moviepy的Python程序使用pyinstaller打包后 ...
随机推荐
- 数据库对应的jdb连接
数据库Database URLJDBC Driver class驱动包 Mysqljdbc:mysql://localhost:port/DBnamecom.mysql.jdbc.Drivermysq ...
- 重磅!阿里P8费心整理Netty实战+指南+项目白皮书PDF,总计1.08G
前言 Netty是一款用于快速开发高性能的网络应用程序的Java框架.它封装了网络编程的复杂性,使网络编程和Web技术的最新进展能够被比以往更广泛的开发人员接触到. Netty不只是一个接口和类的集合 ...
- Docker scratch 无法正常运行golang二进制程序的问题
使用Docker构建容器能够极大的降低运维成本,提高部署效率,同时非常方便对服务的平行扩展.然而在构建容器镜像过程中的,存在着一个难以避免的问题,就是如果使用常见的发行版本作为程序运行的基础环境,那么 ...
- Spring_基于配置文件的方式配置AOP
applicationContext-xml.xml <?xml version="1.0" encoding="UTF-8"?> <bean ...
- vscode jshint 报'import' is only available in ES6 (use 'esversion: 6'). (W119)错误
vue项目用vscode打开代码前出现黄点,js报错 'import' is only available in ES6 (use 'esversion: 6'). (W119) 意思是import属 ...
- Rocket - util - Timer
https://mp.weixin.qq.com/s/Z4JJhZ_jL1lqF1nf_orq9A 简单介绍Timer的实现. 1. 基本功能 实现定时器的功能. 2. Ti ...
- Chisel3 - model - 子模块,顶层模块
https://mp.weixin.qq.com/s/3uUIHW8DmisYARYmNzUZeg 介绍如何构建由模块组成的硬件模型. 1. 子模块 一个模块可以有一个或多个子模块,创建子 ...
- 跨域解决方案 - webpack devServer
1. 定义 如果一个项目中配置了webpack, 那么我们使用 webpack devServer 来配置代理转发请求来达到解决跨域问题的目的 webpack devServer 能够解决跨域问题的根 ...
- Java并发编程 (五) 线程安全性
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.安全发布对象-发布与逸出 1.发布与逸出定义 发布对象 : 使一个对象能够被当前范围之外的代码所使用 ...
- Java实现 LeetCode 313 超级丑数
313. 超级丑数 编写一段程序来查找第 n 个超级丑数. 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数. 示例: 输入: n = 12, primes = [2,7, ...