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
相关推荐
该用户已不存在6 分钟前
Python正在死去,2026年Python还值得学吗?
后端·python
战南诚9 分钟前
flask之“应用上下文,请求上下文”
python·flask
Predestination王瀞潞44 分钟前
Windows环境下Pytorch的配置
人工智能·pytorch·python
施努卡机器视觉1 小时前
SNK施努卡车门自动化安装
运维·自动化
2401_77CN1 小时前
汇川Easy系列PLC封装一阶低通滤波器FC【双线性变换】(定时中断应用,固定步长求解)
笔记·自动化
二川bro1 小时前
特征工程完全手册:2025 Python实战技巧
开发语言·python
袅沫1 小时前
Element-UI 番外表格组件
javascript·vue.js·ui
用户2345267009822 小时前
Python实现异步任务队列深度好文
后端·python
夫唯不争,故无尤也2 小时前
PyTorch 的维度变形一站式入门
人工智能·pytorch·python
熊猫钓鱼>_>2 小时前
从零开始构建RPG游戏战斗系统:实战心得与技术要点
开发语言·人工智能·经验分享·python·游戏·ai·qoder