diff --git a/changelog/7040.improvement.rst b/changelog/7040.improvement.rst new file mode 100644 index 000000000..267eac4c4 --- /dev/null +++ b/changelog/7040.improvement.rst @@ -0,0 +1 @@ +``-k`` no longer matches against the directory containing the test suite. diff --git a/src/_pytest/mark/__init__.py b/src/_pytest/mark/__init__.py index 134ed1876..fd003f68b 100644 --- a/src/_pytest/mark/__init__.py +++ b/src/_pytest/mark/__init__.py @@ -136,7 +136,7 @@ class KeywordMatcher: import pytest for item in item.listchain(): - if not isinstance(item, pytest.Instance): + if not isinstance(item, (pytest.Instance, pytest.Session)): mapped_names.add(item.name) # Add the names added as extra keywords to current or parent items