Skip to content

Commit

Permalink
Do not include the root session with -k
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Apr 8, 2020
1 parent 6356583 commit 37fdb29
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/7040.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The root session item is skipped with ``-k``.
2 changes: 1 addition & 1 deletion src/_pytest/mark/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def from_item(cls, item: "Item") -> "KeywordMapping":
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
Expand Down
7 changes: 2 additions & 5 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,7 @@ def test_no_magic_values(self, testdir):
no double underscored values, like '__dict__',
and no instance values, like '()'.
"""
p = testdir.makepyfile(
"""
def test_one(): assert 1
"""
)
p = testdir.makepyfile("def test_one(): assert 1")

def assert_test_is_not_selected(keyword):
reprec = testdir.inline_run("-k", keyword, p)
Expand All @@ -831,6 +827,7 @@ def assert_test_is_not_selected(keyword):

assert_test_is_not_selected("__")
assert_test_is_not_selected("()")
assert_test_is_not_selected(testdir.tmpdir.basename)


class TestMarkDecorator:
Expand Down

0 comments on commit 37fdb29

Please sign in to comment.