Skip to content

Commit c068823

Browse files
committed
#520
1 parent ff7cbf2 commit c068823

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

src/client/unittests/nosetest/collector.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { CancellationToken } from 'vscode';
88
import { PythonSettings } from '../../common/configSettings';
99

1010
const pythonSettings = PythonSettings.getInstance();
11+
const NOSE_WANT_FILE_PREFIX = 'nose.selector: DEBUG: wantFile ';
12+
const NOSE_WANT_FILE_SUFFIX = '.py? True';
13+
const NOSE_WANT_FILE_SUFFIX_WITHOUT_EXT = '? True';
1114

1215
const argsToExcludeForDiscovery = ['-v', '--verbose',
1316
'-q', '--quiet', '-x', '--stop',
@@ -50,7 +53,8 @@ export function discoverTests(rootDirectory: string, args: string[], token: Canc
5053
}
5154
function processOutput(output: string) {
5255
output.split(/\r?\n/g).forEach((line, index, lines) => {
53-
if (line.trim().startsWith('nose.selector: DEBUG: wantModule <module \'') || index === lines.length - 1) {
56+
if ((line.startsWith(NOSE_WANT_FILE_PREFIX) && line.endsWith(NOSE_WANT_FILE_SUFFIX)) ||
57+
index === lines.length - 1) {
5458
// process the previous lines
5559
parseNoseTestModuleCollectionResult(rootDirectory, logOutputLines, testFiles);
5660
logOutputLines = [''];
@@ -76,31 +80,21 @@ export function discoverTests(rootDirectory: string, args: string[], token: Canc
7680
return execPythonFile(pythonSettings.unitTest.nosetestPath, args.concat(['--collect-only', '-vvv']), rootDirectory, true)
7781
.then(data => {
7882
processOutput(data);
79-
// Exclude tests that don't have any functions or test suites
80-
let indices = testFiles.filter(testFile => {
81-
return testFile.suites.length === 0 && testFile.functions.length === 0;
82-
}).map((testFile, index) => index);
83-
indices.sort();
8483

85-
indices.forEach((indexToRemove, index) => {
86-
let newIndexToRemove = indexToRemove - index;
87-
testFiles.splice(newIndexToRemove, 1);
88-
});
84+
// Exclude tests that don't have any functions or test suites
85+
testFiles = testFiles.filter(testFile => testFile.suites.length > 0 || testFile.functions.length > 0);
8986
return flattenTestFiles(testFiles);
9087
});
9188
}
9289

9390
function parseNoseTestModuleCollectionResult(rootDirectory: string, lines: string[], testFiles: TestFile[]) {
9491
let currentPackage: string = '';
9592
let fileName = '';
96-
let moduleName = '';
9793
let testFile: TestFile;
9894
lines.forEach(line => {
99-
if (line.startsWith('nose.selector: DEBUG: wantModule <module \'')) {
100-
fileName = line.substring(line.indexOf('\' from \'') + '\' from \''.length);
101-
fileName = fileName.substring(0, fileName.lastIndexOf('\''));
102-
moduleName = line.substring(line.indexOf('nose.selector: DEBUG: wantModule <module \'') + 'nose.selector: DEBUG: wantModule <module \''.length);
103-
moduleName = moduleName.substring(0, moduleName.indexOf('\''));
95+
if (line.startsWith(NOSE_WANT_FILE_PREFIX) && line.endsWith(NOSE_WANT_FILE_SUFFIX)) {
96+
fileName = line.substring(NOSE_WANT_FILE_PREFIX.length);
97+
fileName = fileName.substring(0, fileName.lastIndexOf(NOSE_WANT_FILE_SUFFIX_WITHOUT_EXT));
10498

10599
// We need to display the path relative to the current directory
106100
fileName = fileName.substring(rootDirectory.length + 1);

0 commit comments

Comments
 (0)