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
相关推荐
苏州邦恩精密几秒前
GOM三维扫描在制造中的真实价值:让“修模”从经验动作变成数据动作
人工智能·科技·机器学习·3d·自动化·制造
浮云中的神马-潘帅1 分钟前
魔兽世界自动化打地鼠方案
运维·自动化
像风一样的男人@9 分钟前
python --实现代理服务器
git·ui
派大鑫wink18 分钟前
Java 高级编程技巧(生产级实用,覆盖性能、并发、设计、JVM、语法、避坑)
开发语言·python
子嘉11323 分钟前
【无标题】
python
冷小鱼25 分钟前
TensorFlow 2.21 进阶实战:从训练优化到生产部署的完整指南
人工智能·pytorch·python·tensorflow
志栋智能26 分钟前
超自动化安全的技术选型与架构设计指南
运维·安全·自动化
ai_coder_ai30 分钟前
在自动化脚本中操作excel文件
运维·自动化·excel
LT101579744431 分钟前
2026年Web自动化测试工具选型指南:多浏览器兼容解决方案
前端·测试工具·自动化
Chengbei1134 分钟前
AISec真正拟人化全自动渗透工具!支持浏览器交互全自动化挖掘,SQL注入、XSS、越权等。
sql·安全·web安全·网络安全·自动化·系统安全·xss