pytest -v --collect-only, 显示所有被发现的测试

今天执行iOS UI 自动化测试专项时,遇到了这样的报错,明明有这个测试方法为什么找不到呢?

python 复制代码
ERROR: not found: /Users/testmanzhang/PycharmProjects/xxxxxxxxxx/test_open_stream.py::test_ccc_open_stream (no match in any of [<Module test_open_stream.py>])

随着测试代码越来越多,测试方法越来越多,有时在开发完成后就不记得测试模块的结构是什么了,这样会导致在pytest命令行执行测试方法的时候,出现上面的错误。这里有一招,可以随时查看测试模块的结构,就是pytest -v --collect-only,下面是我本地执行后的结果,从这个结果中可以看到新开发的测试方法的位置:

python 复制代码
testmanzhang@TestMandeMBP xxxxxxxxx % pytest -v --collect-only

=================================================================== test session starts ===================================================================
platform darwin -- Python 3.12.1, pytest-8.3.2, pluggy-1.5.0 -- /usr/local/bin/python3.12
cachedir: .pytest_cache
rootdir: /Users/testmanzhang/PycharmProjects/xxxxxxxxx
configfile: pytest.ini
plugins: repeat-0.9.3, anyio-4.6.0, allure-pytest-2.13.5, xonsh-0.18.3
collected 6 items                                                                                                                                         

<Dir xxxxxxxxxx>
  <Module test_xxxx_login.py>
    <Function test_login>
    <Function test_logout>
  <Module test_open_stream.py>
    <Class TestOpenStream>
      开流专项,例如,多次开流,每次记录节点时间
      <Function test_xxx_open_stream>
        :前提条件:① xxxxxxxxxx;② xxxxxxxxxx
        :设备为在线状态,可以开流
      <Function test_xxx_open_stream[xxx]>
        :前提条件:① xxxxxxxxxx;② xxxxxxxxxx
        :设备为在线状态,可以开流
  <Module test_user_center.py>
    <Function test_login>
    <Function test_logout>

需要注意的是,在执行pytest -v --collect-only前,要先进入到工程目录,之后再执行,不然的话它就会一直在collecting,这是我在根目录中执行的结果:

在获取到测试模块的结构之后,我们就可以调整命令行中测试方法的层级了:

python 复制代码
pytest -q -s -ra --count=200  test_open_stream.py::TestOpenStream::test_xxx_open_stream --alluredir=./report/xxx/resource | tee pytest_summary.log
相关推荐
月光船幽幽10 分钟前
呼吸孔设计重塑系统稳定性
python·科技·算法
Bryce学亮15 分钟前
FileLine,基于 Qt 6 + QML 构建的跨平台文件传输与即时通讯工具
数据库·c++·人工智能·python·qt·github
拿铁铁15 分钟前
2026实操场景下平板坡口机噪音问题注意事项梳理汇总
python·电脑
夜雪一千29 分钟前
Python从HTML提取纯文本、去空格、比对内容是否变化:方案+合理性分析
开发语言·python·html
张小泡泡31 分钟前
AUTO_EVAL:面向大语言模型的多层次自动化评测框架
论文阅读·人工智能·语言模型·自然语言处理·自动化·微调
mengpp_1234561 小时前
泵站自动化控制系统:数据安全管控,筑牢水务运行防护墙
物联网·自动化·iot
Zane19941 小时前
同一个 list 为什么能被两个 for 循环同时遍历?一文讲透可迭代对象与迭代器的真相
后端·python
GitLqr2 小时前
iOS 27 强制要求 UISceneDelegate:UIKit 和 Flutter 开发者该如何应对?
flutter·ios·全栈
月走乂山2 小时前
零依赖 GUI:把 OpenCode CLI 变成可视化 AI 任务流水线
python·自动化·ai编程·tkinter·opencode
de之梦-御风2 小时前
【工业自动化平台】 工程设计-依赖注入控制反转(2)
架构·自动化·.net