Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/3936.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix discovery of PyTest tests when package folders are inbetween regular test folders (thanks [Alexander Grund](https://github.com/Flamefire))
24 changes: 15 additions & 9 deletions src/client/unittests/pytest/services/parserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,33 @@ 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;
}

const trimmedLine: string = line.trim();

if (trimmedLine.startsWith('<Package \'')) {
if (trimmedLine.startsWith('<Package \'') || trimmedLine.startsWith('<Module \'') || index === lines.length - 1) {
let packagePrefix : string = '';
if (packages.length > 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('<Package \'')) {
indent = line.indexOf('<');
packagePrefix = this.extractPackageName(trimmedLine, options.cwd);
packages.push({indent: indent, packagePrefix: packagePrefix});
}
}

if (trimmedLine.startsWith('<Module \'') || index === lines.length - 1) {
// Process the previous lines.
this.parsePyTestModuleCollectionResult(options.cwd, logOutputLines, testFiles, parentNodes, packagePrefix);
logOutputLines = [''];
}
if (errorLine.test(line)) {
haveErrors = true;
logOutputLines = [''];
Expand Down
27 changes: 27 additions & 0 deletions src/test/unittests/pytest/pytest_unittest_parser_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,5 +1383,32 @@ export const pytestScenarioData: PytestDiscoveryScenario[] =
"",
"======================== no tests ran in 0.36 seconds ========================="
]
},
{
pytest_version_spec: ">= 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",
"<Module 'aTest/test_upper.py'>",
" <Function 'test_upper_cmd'>",
"<Package '/home/user/test/pytest_scenario/bPackage'>",
" <Module 'testPackage.py'>",
" <Function 'test_package'>",
"<Module 'zTest/test_lower.py'>",
" <Function 'test_lower_cmd'>",
"",
"======================== no tests ran in 0.36 seconds ========================="
]
}
];