From a40d34b118ad37147ad4ee6cf6d6175579f9009c Mon Sep 17 00:00:00 2001 From: Pavel Zaikin Date: Mon, 28 Oct 2019 06:51:44 +0500 Subject: [PATCH] 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 0000000000000..91f488c6896d6 --- /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 39685067c601b..23eb1ee282f07 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 56543ee8b13d1..781d3c831c06b 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__.