列出与Pytest中给定标记关联的所有测试

时间:2017-08-09 19:58:19

标签: python pytest

在Pytest中,我们有pytest --markers命令,它将列出所有可用的标记。

但是,我没有看到列出与x标记关联的测试的命令。文档似乎没有涵盖这个,所以这是Pytest的可能吗?

2 个答案:

答案 0 :(得分:7)

--collect-only-m <marker>结合使用:

$ py.test --collect-only -m x
=========================== test session starts ===========================
platform linux -- Python 3.6.2, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: /home/they4kman/.virtualenvs/tmp-e1f1b42d6ff9bfa/src, inifile:
collected 3 items                                                          
<Module 'test_markers.py'>
  <Function 'test_x'>

====================== no tests ran in 0.00 seconds =======================

答案 1 :(得分:1)

使用以下命令可以获得更清晰的输出结果

(spark_pytest) ALIPL0958:Spark_pytest kapilmathur$ pytest -m integration --collect-only -qq


tests/Servers/test_server_rebuild.py::TestRebuildWithVolumes::test_rebuild_with_volume_attached
tests/Servers/test_server_rebuild.py::TestRebuildWithVolumes::test_post_rebuild_with_second_volume_attach
tests/Servers/test_server_resize.py::TestResizeWithVolumes::test_resize_with_volume_attached
tests/Servers/test_server_resize.py::TestResizeWithVolumes::test_post_resize_with_second_volume_attach

enter image description here