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?
To use markers, we have to import pytest module in the test file. We can define our own marker names to the tests and run the tests having those marker names. -m <markername> represents the marker name of the tests to be executed.
Multiple custom markers can be registered, by defining each one in its own line, as shown in above example. You can ask which markers exist for your test suite - the list includes our just defined webtest and slow markers: $ pytest --markers @pytest. mark.
Pytest allows to group tests using markers. pytest.mark decorator is used to mark a test function with custom metadata like @pytest.mark.smoke. This is very handy when we want to run only a subset of tests like "smoke tests" to quickly verify if the changes made by the developer not breaking any major functionalities.
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 =======================
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With