diff --git a/news/2 Fixes/8425.md b/news/2 Fixes/8425.md new file mode 100644 index 000000000000..ca24301e234a --- /dev/null +++ b/news/2 Fixes/8425.md @@ -0,0 +1 @@ +Do not ignore pytest plugins tests, like pep8. (thanks [Pavel Zaikin](https://github.com/zztalker/)) diff --git a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py index 87e439e30c7e..6be57c00fce4 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py +++ b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py @@ -155,12 +155,20 @@ def parse_item( """ # _debug_item(item, showsummary=True) kind, _ = _get_item_kind(item) - # Skip plugin generated tests + # Skip unexpected kind tests if kind is None: return None, None - (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id( - item.nodeid, kind - ) + + if kind == "plugin_node": + (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id( + item.nodeid + "::" + item.location[2], kind + ) + + else: + + (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id( + item.nodeid, kind + ) # Note: testfunc does not necessarily match item.function.__name__. # This can result from importing a test function from another module. @@ -394,7 +402,7 @@ def _parse_node_id( parents.append(node) funcid, funcname, _ = node parameterized = testid[len(funcid) :] - elif kind == "function": + elif kind == "function" or kind == "plugin_node": funcname = name else: raise should_never_reach_here( @@ -536,6 +544,12 @@ def _get_item_kind(item): elif isinstance(item, pytest.Function): # We *could* be more specific, e.g. "method", "subtest". return "function", False + elif isinstance(item, _pytest.nodes.Item) and isinstance(item, _pytest.nodes.File): + # item._nodeid = item.nodeid + "::" + item.location[2] + item.name = item.name.replace(PATH_SEP, ".") + if item.name[-3:] == ".py": + item.name = item.name[:-3] + return "plugin_node", False else: return None, False diff --git a/src/client/testing/common/xUnitParser.ts b/src/client/testing/common/xUnitParser.ts index 76ed830672ba..f76f1c51fdbd 100644 --- a/src/client/testing/common/xUnitParser.ts +++ b/src/client/testing/common/xUnitParser.ts @@ -115,18 +115,30 @@ function updateTests(tests: Tests, testSuiteResult: TestSuiteResult) { updateResultInfo(testFunc, testcase); updateResultStatus(testFunc, testcase); } else { - // Possible we're dealing with nosetests, where the file name isn't returned to us - // When dealing with nose tests - // It is possible to have a test file named x in two separate test sub directories and have same functions/classes - // And unforutnately xunit log doesn't ouput the filename - - // result = tests.testFunctions.find(fn => fn.testFunction.name === testcase.$.name && - // fn.parentTestSuite && fn.parentTestSuite.name === testcase.$.classname); - - // Look for failed file test - const fileTest = testcase.$.file && tests.testFiles.find((file) => file.nameToRun === testcase.$.file); - if (fileTest && testcase.error) { - updateResultStatus(fileTest, testcase); + // For pytest plugins like PEP8 it generate node for whole file, and classname == '' in it + if (testcase.$.classname === '') { + const testFuncForPlugin = findTestFunction(tests.testFunctions, testcase.$.name, testcase.$.name); + if (testFuncForPlugin) { + if (testcase.$.line === '-1') { + testcase.$.line = '1'; + } + updateResultInfo(testFuncForPlugin, testcase); + updateResultStatus(testFuncForPlugin, testcase); + } + } else { + // Possible we're dealing with nosetests, where the file name isn't returned to us + // When dealing with nose tests + // It is possible to have a test file named x in two separate test sub directories and have same functions/classes + // And unforutnately xunit log doesn't ouput the filename + + // result = tests.testFunctions.find(fn => fn.testFunction.name === testcase.$.name && + // fn.parentTestSuite && fn.parentTestSuite.name === testcase.$.classname); + + // Look for failed file test + const fileTest = testcase.$.file && tests.testFiles.find((file) => file.nameToRun === testcase.$.file); + if (fileTest && testcase.error) { + updateResultStatus(fileTest, testcase); + } } } });