【pytest】 pytest拓展功能 pycharm PermissionError: [Errno 13] Permission denied:

目录

1. pytest-html

 1.1 PermissionError: [Errno 13] Permission denied: 'D:\\software\\python3\\anconda3\\Lib\\site-packages\\pytest_html\\__pycache__\\tmp_ttoasov'

1.2错误原因

 2.  失败用例重试 

 3.  用例并行执行  pytest-parallel


1. pytest-html

管理员打开 Anaconda  Prompt  输入: pip   install pytest-html

 查询是否安装成功:

 1.1 PermissionError: [Errno 13] Permission denied: 'D:\\software\\python3\\anconda3\\Lib\\site-packages\\pytest_html\\__pycache__\\tmp_ttoasov'

1.检查对应路径下的文件是否存在,且被占用。如果文件不存在,就找到对应文件即可;如果文件存在,被占用,将占用程序暂时关闭。

2.修改cmd的权限,以管理员身份运行。

3.检查是否是打开了文件夹。

hhhhhhh
Traceback (most recent call last):
  File "D:\software\python3\anconda3\lib\tempfile.py", line 256, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
PermissionError: [Errno 13] Permission denied: 'D:\\software\\python3\\anconda3\\Lib\\site-packages\\pytest_html\\__pycache__\\tmp_ttoasov'

During handling of the above exception, another exception occurred:

pytest_html\\__pycache__\\tmp_ttoasov    没有这个文件 删除这个文件夹再试试

1.2错误原因

1、文件被占用

2、文件找不到

3、无权限访问

4、打开的不是文件,而是一个目录

D:\software\python3\anconda3\Lib 

参考:Python报错:PermissionError: [Errno 13] Permission denied的解决办法_python_脚本之家 

1.3解决方案

Python 3.6 解决"PermissionError: [Errno 13] Permission denied" - 简书

管理员方式运行 pycharm 

 

import pytest

if __name__=='__main__':

    pytest.main(['-s','-v', './test_project','--html=./report/result.html'])

 2.  失败用例重试 

(base) C:\WINDOWS\system32>pip install  pytest-rerunfailures

 

pytest -v ./rerunfailures  --reruns 10 

PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example> pytest -v ./rerunfailures  --reruns 10
======================================================================== test session starts ========================================================================
platform win32 -- Python 3.10.9, pytest-7.1.2, pluggy-1.0.0 -- D:\software\python3\anconda3\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.10.9', 'Platform': 'Windows-10-10.0.19045-SP0', 'Packages': {'pytest': '7.1.2', 'pluggy': '1.0.0'}, 'Plugins': {'anyio': '3.5.0', 'html': '4.0
.2', 'metadata': '3.0.0', 'rerunfailures': '12.0'}, 'JAVA_HOME': 'D:\\software\\Java\\jdk1.8.0_151'}
rootdir: E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example
plugins: anyio-3.5.0, html-4.0.2, metadata-3.0.0, rerunfailures-12.0
collected 1 item                                                                                                                                                     

rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun RERUN                                                                                                     [100%]
rerunfailures/test_rerunfailures.py::test_fail_rerun FAILED                                                                                                    [100%]

============================================================================= FAILURES ==============================================================================
__________________________________________________________________________ test_fail_rerun __________________________________________________________________________

    def test_fail_rerun():
>       assert 2+2==1
E       assert (2 + 2) == 1

rerunfailures\test_rerunfailures.py:2: AssertionError
====================================================================== short test summary info ======================================================================
FAILED rerunfailures/test_rerunfailures.py::test_fail_rerun - assert (2 + 2) == 1
==================================================================== 1 failed, 10 rerun in 0.75s ====================================================================
PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example>

 3.  用例并行执行  pytest-parallel

pip install    pytest-parallel

运行  : pytest  -q test_paralle.py

web 自动化 并行执行可能会相互干扰。少用

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PyCharm中运行Python程序时,出现了"PermissionError: [Errno 13 Permission denied"的错误。这个错误通常是由于权限限制导致的。有几种可能的原因和解决方法。 首先,这个错误可能是由于尝试读取或写入被保护的文件或文件夹而导致的。你可以尝试以管理员权限运行PyCharm,这样可以解决一些权限问题。 其次,这个错误也可能是由于尝试在不存在的文件或文件夹上执行操作而导致的。你可以检查相关路径,确保你要读取或写入的文件或文件夹确实存在。如果不存在,你可以手动创建它们。 另外,还有一种可能是由于代码中的错误导致的。你可以检查你的代码,确保你在使用shutil.copy()或shutil.copyfile()函数时传递了正确的文件路径和目标路径。 总结来说,解决"PermissionError: [Errno 13 Permission denied"错误的方法包括以管理员权限运行PyCharm、确保要读取或写入的文件或文件夹存在、检查代码中的错误。希望这些方法可以帮助你解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Pycharm使用-错误“PermissionError: [Errno 13] Permission denied”排查](https://blog.csdn.net/mystonelxj/article/details/120738072)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [解决PermissionError: [Errno 13] Permission denied](https://blog.csdn.net/qq_37700257/article/details/123301596)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值