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

目录

[1. pytest-html](#1. pytest-html)

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

1.2错误原因

[2. 失败用例重试](#2. 失败用例重试)

[3. 用例并行执行 pytest-parallel](#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 自动化 并行执行可能会相互干扰。少用

相关推荐
努力搬砖的咸鱼9 小时前
从零开始搭建 Pytest 测试框架(Python 3.8 + PyCharm 版)
python·pycharm·pytest
FINE!(正在努力!)2 天前
PyTest框架学习
学习·pytest
程序员杰哥3 天前
接口自动化测试之pytest 运行方式及前置后置封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
测试老哥3 天前
Pytest+Selenium UI自动化测试实战实例
自动化测试·软件测试·python·selenium·测试工具·ui·pytest
水银嘻嘻3 天前
07 APP 自动化- appium+pytest+allure框架封装
python·appium·自动化·pytest
天才测试猿4 天前
接口自动化测试之pytest接口关联框架封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
not coder5 天前
Pytest Fixture 详解
数据库·pytest
not coder5 天前
pytest 常见问题解答 (FAQ)
开发语言·python·pytest
程序员的世界你不懂5 天前
(1)pytest简介和环境准备
pytest
not coder5 天前
Pytest Fixture 是什么?
数据库·oracle·pytest