You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CMD运行Pytest遇两类错误:命令未识别与权限拒绝

解决CMD中运行Pytest的两类错误

一、'py.test' is not recognized as an internal or external command... 错误解决

  • 确认pytest已安装:执行pip list查看已安装包,未安装则运行pip install pytest。
  • 替换命令:新版本pytest不再使用py.test,直接用pytest命令启动测试。
  • 配置环境变量:找到Python安装目录下的Scripts文件夹(如C:\Python39\Scripts),将其路径添加到系统环境变量PATH中,重启CMD后重试。

二、ERROR: PermissionError: [WinError 5] Access is denied. 错误解决

  • 管理员身份运行CMD:右键CMD图标,选择「以管理员身份运行」后执行pytest。
  • 检查文件/目录权限:右键测试文件所在文件夹,进入「属性」-「安全」,确保当前用户拥有读写权限。
  • 转移测试文件:不要在系统保护目录(如C:\Windows、Program Files)下运行测试,移到个人用户目录(如C:\Users\你的用户名\Documents)再执行。
  • 使用虚拟环境:隔离依赖环境,避免权限冲突,执行以下命令:
    python -m venv test_env
    test_env\Scripts\activate
    pip install pytest
    pytest
    

内容的提问来源于stack exchange,提问作者Bhakti Lad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 10:42:02