Skip to content

Commit 355a325

Browse files
zztalkerericsnowcurrently
authored andcommitted
Skip tests generated by pytest plugins during discovery. (#8242)
For #7287.
1 parent 96d19a5 commit 355a325

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

news/2 Fixes/7287.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
During test discovery, ignore tests generated by pytest plugins (like pep8).
2+
Tests like that were causing discovery to fail.

pythonFiles/testing_tools/adapter/pytest/_discovery.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def pytest_collection_modifyitems(self, session, config, items):
7878
self._tests.reset()
7979
for item in items:
8080
test, parents = self.parse_item(item)
81-
self._tests.add_test(test, parents)
81+
if test is not None:
82+
self._tests.add_test(test, parents)
8283

8384
# This hook is not specified in the docs, so we also provide
8485
# the "modifyitems" hook just in case.
@@ -92,4 +93,5 @@ def pytest_collection_finish(self, session):
9293
self._tests.reset()
9394
for item in items:
9495
test, parents = self.parse_item(item)
95-
self._tests.add_test(test, parents)
96+
if test is not None:
97+
self._tests.add_test(test, parents)

pythonFiles/testing_tools/adapter/pytest/_pytest_item.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def parse_item(item, #*,
152152
"""
153153
#_debug_item(item, showsummary=True)
154154
kind, _ = _get_item_kind(item)
155+
# Skip plugin generated tests
156+
if kind is None:
157+
return None, None
155158
(nodeid, parents, fileid, testfunc, parameterized
156159
) = _parse_node_id(item.nodeid, kind)
157160
# Note: testfunc does not necessarily match item.function.__name__.

0 commit comments

Comments
 (0)