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。

相关推荐
liangshanbo121511 小时前
[特殊字符] macOS 上的 zoxide:智能目录跳转终极指南
macos·策略模式
补三补四11 小时前
pytest应用实践
pytest
pop_xiaoli12 小时前
【iOS】类与对象底层
macos·ios·objective-c·cocoa·xcode
一招定胜负14 小时前
视频转写+LLM分析:课堂录音自动化处理实现
macos·ios·xcode
坚果派·白晓明14 小时前
在 macOS 中搭建鸿蒙 PC 三方库交叉编译开发环境
macos·华为·harmonyos
blackorbird14 小时前
通过攻陷合法网站传播的新型iOS漏洞利用工具包DarkSword
macos·ios·objective-c·cocoa
ricky_fan1 天前
(OpenAI)Codex 安装、部署使用方式
python·macos·conda·vim
音源部落1 天前
Cubase15 R2R/VR一键安装完整版本下载安装Nuendo 14最新版本下载安装支持Win/Mac 双系统版本加104G原厂音源Mac系统不关SIP安装编曲软件Cubase 15.0.10下载
macos·vr·cubase·cubase15·nuendo·nuendo14
Lary_c2 天前
【测试自动化】pytest + Allure 完整学习指南
运维·自动化·pytest
代码AI弗森2 天前
Mac 长时间处在高温运行会怎么样?
macos