运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该。百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢。
报错信息如下:

网上解决方法是这样的:
1. 命名py脚本时,不要与python预留字,模块名等相同
2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可
PS:此方法在我的问题上解决不了。
自己的解决方法:
卸载 and 重装 pytest库
1、打开cmd,输入命令:pip uninstall pytest
2、若提示删除失败,找到D:\python\Lib\site-packages的【pytest】文件(这里的路径根据个人安装路径不同而不同),将该文件直接删除,然后再次重复第一步即可。
3、为了查看是否卸载完成,输入pip list 查看安装的所有模块,如果卸载模块操作成功,则不会再看到【pytest】模块
4、再使用 pip install pytest 命令重新安装
运行pytest后,展示了版本号,则安装成功

运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"的更多相关文章
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'
一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- 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>", ...
随机推荐
- Tomcat 方式部署 Solo 博客系统总结
此篇为Tomcat部署方式,另有Docker部署方式,请参考文章<Docker 方式部署 Solo 博客系统总结> 一.环境和文件准备 服务器:购买的阿里云服务器,系统为Linux(C ...
- 洛谷 P1177 【模板】快速排序
这道题用传统快排(如下所示)的结果就是最后三个点TLE: void swap(int &a, int &b) { int tmp = a; a = b; b = tmp; } void ...
- Nacos(三):Nacos与OpenFeign的对接使用
前言 上篇文章中,简单介绍了如何在SpringCloud项目中接入Nacos作为注册中心,其中服务消费者是通过RestTemplate+Ribbon的方式来进行服务调用的. 实际上在日常项目中服务间调 ...
- python学习之路(2)---字符编码
二进制编码 bin(300) python计算二进制编码,十进制转2进制 一个二进制位就是1bit 1bit代表了8个字节,00001111 1bit = 1bytes 缩写1b 1kb ...
- .NET Core 很酷,你不得不知!
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://www.infoq.cn/article/xPTBAR9-oJcVtUjTQ0tK ...
- sea.js的同步魔法
前些时间也是想写点关于CMD模块规范的文字,以便帮助自己理解.今天看到一篇知乎回答,算是给了我一点启发. 同步写法却不阻塞? 先上一个sea.js很经典的模块写法: // 定义一个模块 define( ...
- CentOS7配置网络ip地址
CentOS7配置网络ip地址 CentOS 7.x版本中没有ifcfg-eth0文件 只有ifcfg-ens33文件(为了符合日常习惯) (1)将文件ifcfg-ens33重命名为ifcfg-eth ...
- Python-demo(video)
#!/usr/bin/env python# #-*-coding:utf-8-*-import requestsimport randomimport timedef get_json(url): ...
- CentOS -- RocketMQ HA & Monitoring
RocketMQ Architecture NameServer Cluster Name Servers provide lightweight service discovery and rout ...
- Docker容器技术的核心
容器技术的核心 所谓容器,其实是由Linux Namespace.Linux Cgroups和rootfs三种技术构建出来的进程的隔离环境 对于Docker项目来说,其实最核心就是为待创建的用户进程: ...