From 2f776cdcd054fd5c704f7a31606b18b1764bbc72 Mon Sep 17 00:00:00 2001 From: Pavel Zaikin Date: Mon, 28 Oct 2019 06:51:44 +0500 Subject: [PATCH 1/2] Skip tests generated by plugins (like pep8) for discovery command. To do not fail on discovery command and do not track their results. --- news/2 Fixes/7287.md | 1 + pythonFiles/testing_tools/adapter/pytest/_discovery.py | 6 ++++-- pythonFiles/testing_tools/adapter/pytest/_pytest_item.py | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 news/2 Fixes/7287.md diff --git a/news/2 Fixes/7287.md b/news/2 Fixes/7287.md new file mode 100644 index 000000000000..91f488c6896d --- /dev/null +++ b/news/2 Fixes/7287.md @@ -0,0 +1 @@ +Discovering tests failed when pytest plugins generate tests (like pep8). \ No newline at end of file diff --git a/pythonFiles/testing_tools/adapter/pytest/_discovery.py b/pythonFiles/testing_tools/adapter/pytest/_discovery.py index 39685067c601..23eb1ee282f0 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_discovery.py +++ b/pythonFiles/testing_tools/adapter/pytest/_discovery.py @@ -78,7 +78,8 @@ def pytest_collection_modifyitems(self, session, config, items): self._tests.reset() for item in items: test, parents = self.parse_item(item) - self._tests.add_test(test, parents) + if test is not None: + self._tests.add_test(test, parents) # This hook is not specified in the docs, so we also provide # the "modifyitems" hook just in case. @@ -92,4 +93,5 @@ def pytest_collection_finish(self, session): self._tests.reset() for item in items: test, parents = self.parse_item(item) - self._tests.add_test(test, parents) + if test is not None: + self._tests.add_test(test, parents) diff --git a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py index 56543ee8b13d..781d3c831c06 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py +++ b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py @@ -152,6 +152,9 @@ def parse_item(item, #*, """ #_debug_item(item, showsummary=True) kind, _ = _get_item_kind(item) + # Skip plugin generated tests + if kind is None: + return None, None (nodeid, parents, fileid, testfunc, parameterized ) = _parse_node_id(item.nodeid, kind) # Note: testfunc does not necessarily match item.function.__name__. From 9ab4773f57f99df3a116ac44f6ff16f8f6eef707 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 6 Nov 2019 11:33:12 -0700 Subject: [PATCH 2/2] Update 7287.md --- news/2 Fixes/7287.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/news/2 Fixes/7287.md b/news/2 Fixes/7287.md index 91f488c6896d..8f47a5e12e11 100644 --- a/news/2 Fixes/7287.md +++ b/news/2 Fixes/7287.md @@ -1 +1,2 @@ -Discovering tests failed when pytest plugins generate tests (like pep8). \ No newline at end of file +During test discovery, ignore tests generated by pytest plugins (like pep8). +Tests like that were causing discovery to fail.