Wunderbread
Wunderbread

Reputation: 1070

Listing all tests associated with a given marker in Pytest

In Pytest we have the pytest --markers command which will list all of the markers that are available for use.

However, I am not seeing a command to list tests associated with x marker. The documentation didn't appear to cover this so is this a possibility in Pytest?

Upvotes: 6

Views: 4616

Answers (2)

nomoreabond2017
nomoreabond2017

Reputation: 150

A more cleaner output can be achieved by using:

(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

Upvotes: 3

theY4Kman
theY4Kman

Reputation: 6105

Use --collect-only in conjuction with -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 =======================

Upvotes: 11

Related Questions