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 select tests by name

  • --collect-only

  • -k

  • --collect-only - only list the tests, don't run them yet.

  • -k select by name


def test_database_read():
    assert True

def test_database_write():
    assert True

def test_database_forget():
    assert True

def test_ui_access():
    assert True

def test_ui_forget():
    assert True
pytest --collect-only test_by_name.py
    test_database_read
    test_database_write
    test_database_forget
    test_ui_access
    test_ui_forget
pytest --collect-only -k database test_by_name.py
    test_database_forget
    test_database_read
    test_database_write
pytest --collect-only -k ui test_by_name.py
    test_ui_access
    test_ui_forget
pytest --collect-only -k forget test_by_name.py
    test_database_forget
    test_ui_forget
pytest --collect-only -k "forget or read" test_by_name.py
    test_database_read
    test_database_forget
    test_ui_forget