From ee596a663c8425e91d3f0acd21d2b3ca3360a188 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Wed, 9 Jan 2019 18:14:35 +0100 Subject: [PATCH] Fix discovery of PyTests with packages inbetween folders Fixes #3936 --- news/2 Fixes/3936.md | 1 + .../pytest/services/parserService.ts | 24 ++++++++++------- .../pytest/pytest_unittest_parser_data.ts | 27 +++++++++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 news/2 Fixes/3936.md diff --git a/news/2 Fixes/3936.md b/news/2 Fixes/3936.md new file mode 100644 index 000000000000..b0361fb2ab10 --- /dev/null +++ b/news/2 Fixes/3936.md @@ -0,0 +1 @@ +Fix discovery of PyTest tests when package folders are inbetween regular test folders (thanks [Alexander Grund](https://github.com/Flamefire)) diff --git a/src/client/unittests/pytest/services/parserService.ts b/src/client/unittests/pytest/services/parserService.ts index 1b795ff6fd50..ec5d87e8a1e6 100644 --- a/src/client/unittests/pytest/services/parserService.ts +++ b/src/client/unittests/pytest/services/parserService.ts @@ -30,7 +30,7 @@ export class TestsParser implements ITestsParser { let haveErrors = false; - let packagePrefix: string = ''; + const packages: { indent: number; packagePrefix: string }[] = []; content.split(/\r?\n/g).forEach((line, index, lines) => { if (options.token && options.token.isCancellationRequested) { return; @@ -38,19 +38,25 @@ export class TestsParser implements ITestsParser { const trimmedLine: string = line.trim(); - if (trimmedLine.startsWith(' 0) { + packagePrefix = packages[packages.length - 1].packagePrefix; + } // Process the previous lines. this.parsePyTestModuleCollectionResult(options.cwd, logOutputLines, testFiles, parentNodes, packagePrefix); + let indent = line.indexOf('<'); + while (packages.length > 0 && packages[packages.length - 1].indent >= indent) { + packages.pop(); + } logOutputLines = ['']; - - packagePrefix = this.extractPackageName(trimmedLine, options.cwd); + if (trimmedLine.startsWith('= 3.7", + platform: PytestDataPlatformType.NonWindows, + description: "With package inbetween.", + rootdir: "/home/user/test/pytest_scenario", + test_functions: [ + "aTest/test_upper.py::test_upper_cmd", + "bPackage/testPackage.py::test_package", + "zTest/test_lower.py::test_lower_cmd" + ], + functionCount: 3, + stdout: [ + "============================= test session starts =============================", + "platform win32 -- Python 3.7.0, pytest-3.7.4, py-1.6.0, pluggy-0.7.1", + "rootdir: /home/user/test/pytest_scenario, inifile:", + "collected 3 items", + "", + " ", + "", + " ", + " ", + "", + " ", + "", + "======================== no tests ran in 0.36 seconds =========================" + ] } ];