mac终端使用pytest执行iOS UI自动化测试方法

1、安装pytest-repeat插件:

pip install pytest-repeat

2、安装allure-pytest插件:

pip install allure-pytest

3、打开终端:

pytest -q -s -ra --count=100 test_open_stream.py --alluredir=./report/CXL

-q:表示"quiet mode"(安静模式),减少输出信息,只显示最小的结果信息。

-s:允许在控制台中输出 print 语句的内容,方便调试。

-ra:显示测试报告摘要,包括通过、失败、错误等详细信息。

--count=100:表示将 test_open_stream.py 测试运行 100 次。

--alluredir=./report/C6L:将测试结果保存到 ./report/CXL 目录中,以便之后生成 Allure 报告。

4、在测试完成后,生成 Allure 报告来查看详细的测试结果:

allure serve ./report/CXL

在查看报告之前需要安装allure插件:

brew install allure

查看是否安装成功:

allure --version

【问题】

allure安装时间较长,需要网络稳定,第一次没有安装成功。第二次安装allure过程出现如下报错:

==> Pouring python@3.12--3.12.7_1.sonoma.bottle.tar.gz Error: The brew link step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/2to3-3.12 Target /usr/local/bin/2to3-3.12 already exists. You may want to remove it: rm '/usr/local/bin/2to3-3.12' To force the link and overwrite all conflicting files: brew link --overwrite python@3.12 To list all files that would be deleted: brew link --overwrite python@3.12 --dry-run Possible conflicting files are: /usr/local/bin/2to3-3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/2to3-3.12 /usr/local/bin/idle3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/idle3.12 /usr/local/bin/pydoc3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/pydoc3.12 /usr/local/bin/python3.12 -> /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 /usr/local/bin/python3.12-config -> /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12-config

【解决】

rm /usr/local/bin/2to3-3.12

rm /usr/local/bin/idle3.12

rm /usr/local/bin/pydoc3.12

rm /usr/local/bin/python3.12

rm /usr/local/bin/python3.12-config

brew link python@3.12

【备注】

上面的报错原因是我之前安装的python版本不是通过homebrew安装的,在后续使用homebrew安装其他插件时会弹出上面的提示,即homebrew希望有它来管理python版本。按照上面的解决方法,可以解决问题,但是后来在使用pytest执行脚本的时候报错:

testmanzhang@TestMandeMBP practiceUICatalog % pytest

Traceback (most recent call last):

File "/Library/Frameworks/Python.framework/Versions/3.12/bin/pytest", line 5, in <module>

from pytest import console_main

之前安装的pytest插件不能用了,后来恢复了原来的符号连接:

sudo rm /usr/local/bin/2to3-3.12

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/2to3-3.12 /usr/local/bin/2to3-3.12

sudo rm /usr/local/bin/idle3.12

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/idle3.12 /usr/local/bin/idle3.12

sudo rm /usr/local/bin/pydoc3.12

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/pydoc3.12 /usr/local/bin/pydoc3.12

sudo rm /usr/local/bin/python3.12

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 /usr/local/bin/python3.12

sudo rm /usr/local/bin/python3.12-config

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12-config /usr/local/bin/python3.12-config

所以建议大家使用homebrew安装python。

相关推荐
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
甜于酸13 小时前
MuMu模拟器Pro for Mac 安卓手机平板模拟器
android·macos·智能手机
渔夫阿布13 小时前
在MAC上面通过HomeBrew安装node和npm@指定版本
前端·macos·npm
waicsdn_haha14 小时前
TeX Live 2025 最新版安装与中文环境配置全教程(Windows/Mac/Linux)
linux·windows·macos·论文笔记·sublime text·mdk·嵌入式开发工具
xinyu39118 小时前
iOS Framework代码中加载图片资源
macos·ios·cocoa
励志前端小黑哥21 小时前
brew search报错,xcrun:error:invalid active developer path CommandLineTools
macos
开源优测1 天前
Pytest中5种不同的方法解析JSON数据
log4j·json·pytest
不求大富大贵只求富可敌国1 天前
Gtest, Junit,以及pytest对比理解
junit·pytest
至天1 天前
MacPorts 创建自定义 Portfile 安装 RoadRunner
macos·安装·macports·roadrunner·portfile