Skip to content

-k expression ignores directory paths #14218

@VladimirPodolian

Description

@VladimirPodolian
  • a detailed description of the bug or problem you are having

The -k expression does not work with directory paths. For example, pytest -k '/common' does not collect any tests from the /common folder.


  • output of pip list from the virtual environment you are using
Package    Version
---------- -------
attrs      25.4.0
iniconfig  2.3.0
packaging  26.0
pip        25.3
pluggy     1.6.0
py         1.11.0
Pygments   2.19.2
pytest     9.0.2
setuptools 80.9.0
tomli      2.4.0
wheel      0.45.1


  • pytest and operating system versions
    MacOS 26.2 (25C56)
    pytest 9.0.2

  • minimal example if possible

Files tree:
└── tests
├── common
│   └── test_common.py
├── desktop
│   └── test_desktop.py
└── mobile
└── mobile_test.py

# test_common.py:
def test_case_common():
    pass

# test_desktop.py:
def test_case_1():
    pass

# test_mobile.py:
def test_case_2():
    pass

Outputs:

/check-pytest [5]> pytest -k '/common'
============================= test session starts =============================
platform darwin -- Python 3.12.4, pytest-9.0.2, pluggy-1.6.0
rootdir: /check-pytest
collected 3 items / 3 deselected / 0 selected         
============================= 3 deselected in 0.01s =============================

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: selectionrelated to test selection from the command linetype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions