Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pytest use markers to select tests

  • -m select by mark
import pytest

@pytest.mark.long
def test_database_read():
    assert True

============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/gabor/work/slides/python/examples/pytest
plugins: flake8-1.0.6, dash-1.17.0
collected 1 item

test_marker.py .                                                         [100%]

=============================== warnings summary ===============================
test_marker.py:3
  test_marker.py:3: PytestUnknownMarkWarning: Unknown pytest.mark.long - is this a typo?
    You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.long

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================= 1 passed, 1 warning in 0.00s =========================
  • We need to declare them in the pytest.ini to avoid the warning

{% embed include file="src/examples/pytest/markers/pytest.ini)