Skip to content

Commit 24dd3f4

Browse files
committed
fix #307
1 parent 512e584 commit 24dd3f4

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎src/client/unittests/common/baseTestManager.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export abstract class BaseTestManager {
6262

6363
this.cancellationTokenSource = new vscode.CancellationTokenSource();
6464
this.createCancellationToken();
65-
return this.discoverTestsPromise = this.discoverTestsImpl()
65+
return this.discoverTestsPromise = this.discoverTestsImpl(ignoreCache)
6666
.then(tests => {
6767
this.tests = tests;
6868
this._status = TestStatus.Idle;
@@ -115,7 +115,7 @@ export abstract class BaseTestManager {
115115
return Promise.reject(reason);
116116
});
117117
}
118-
abstract discoverTestsImpl(): Promise<Tests>;
118+
abstract discoverTestsImpl(ignoreCache: boolean): Promise<Tests>;
119119
public runTest(testsToRun?: TestsToRun): Promise<Tests>;
120120
public runTest(runFailedTests?: boolean): Promise<Tests>;
121121
public runTest(args: any): Promise<Tests> {
@@ -155,7 +155,8 @@ export abstract class BaseTestManager {
155155
this.createCancellationToken();
156156
// If running failed tests, then don't clear the previously build UnitTests
157157
// If we do so, then we end up re-discovering the unit tests and clearing previously cached list of failed tests
158-
const clearDiscoveredTestCache = runFailedTests === true ? false : true;
158+
// Similarly, if running a specific test or test file, don't clear the cache (possible tests have some state information retained)
159+
const clearDiscoveredTestCache = runFailedTests || moreInfo.Run_Specific_File || moreInfo.Run_Specific_Class || moreInfo.Run_Specific_Function ? false : true;
159160
return this.discoverTests(clearDiscoveredTestCache, true)
160161
.catch(reason => {
161162
if (this.cancellationToken && this.cancellationToken.isCancellationRequested) {

‎src/client/unittests/nosetest/main.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class TestManager extends BaseTestManager {
1313
constructor(rootDirectory: string, outputChannel: vscode.OutputChannel) {
1414
super('nosetest', rootDirectory, outputChannel);
1515
}
16-
discoverTestsImpl(): Promise<Tests> {
16+
discoverTestsImpl(ignoreCache: boolean): Promise<Tests> {
1717
let args = settings.unitTest.pyTestArgs.slice(0);
1818
return discoverTests(this.rootDirectory, args, this.cancellationToken);
1919
}

‎src/client/unittests/pytest/collector.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const settingsInArgsToExcludeForDiscovery = ['--maxfail', '--capture',
1919
'-r ', '--report', '--tb', '--color', '--durations', '--pastebin',
2020
'--junit-xml=path', '--junit-prefix', '--result-log'];
2121

22-
export function discoverTests(rootDirectory: string, args: string[], token: vscode.CancellationToken): Promise<Tests> {
22+
export function discoverTests(rootDirectory: string, args: string[], token: vscode.CancellationToken, ignoreCache: boolean): Promise<Tests> {
2323
let logOutputLines: string[] = [''];
2424
let testFiles: TestFile[] = [];
2525
let parentNodes: { indent: number, item: TestFile | TestSuite }[] = [];
@@ -39,7 +39,9 @@ export function discoverTests(rootDirectory: string, args: string[], token: vsco
3939
}
4040
return true;
4141
});
42-
42+
if (ignoreCache && args.indexOf('--cache-clear') === -1) {
43+
args.push('--cache-clear');
44+
}
4345
function processOutput(output: string) {
4446
output.split(/\r?\n/g).forEach((line, index, lines) => {
4547
if (token && token.isCancellationRequested) {
@@ -113,7 +115,7 @@ function parsePyTestModuleCollectionError(rootDirectory: string, lines: string[]
113115
fileName = fileName.substr(0, fileName.lastIndexOf(' '));
114116

115117
const currentPackage = convertFileToPackage(fileName);
116-
const fullyQualifiedName = path.isAbsolute(fileName) ? fileName : path.resolve(rootDirectory, fileName)
118+
const fullyQualifiedName = path.isAbsolute(fileName) ? fileName : path.resolve(rootDirectory, fileName);
117119
const testFile = {
118120
functions: [], suites: [], name: fileName, fullPath: fullyQualifiedName,
119121
nameToRun: fileName, xmlName: currentPackage, time: 0, errorsWhenDiscovering: lines.join('\n')

‎src/client/unittests/pytest/main.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export class TestManager extends BaseTestManager {
1111
constructor(rootDirectory: string, outputChannel: vscode.OutputChannel) {
1212
super('pytest', rootDirectory, outputChannel);
1313
}
14-
discoverTestsImpl(): Promise<Tests> {
14+
discoverTestsImpl(ignoreCache: boolean): Promise<Tests> {
1515
let args = settings.unitTest.pyTestArgs.slice(0);
16-
return discoverTests(this.rootDirectory, args, this.cancellationToken);
16+
return discoverTests(this.rootDirectory, args, this.cancellationToken, ignoreCache);
1717
}
1818
runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean): Promise<any> {
1919
let args = settings.unitTest.pyTestArgs.slice(0);

‎src/client/unittests/unittest/main.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ export class TestManager extends BaseTestManager {
1111
constructor(rootDirectory: string, outputChannel: vscode.OutputChannel) {
1212
super('pytest', rootDirectory, outputChannel);
1313
}
14-
discoverTestsImpl(): Promise<Tests> {
14+
discoverTestsImpl(ignoreCache: boolean): Promise<Tests> {
1515
let args = settings.unitTest.unittestArgs.slice(0);
1616
return discoverTests(this.rootDirectory, args, this.cancellationToken);
1717
}
1818
runTestImpl(tests: Tests, testsToRun?: TestsToRun, runFailedTests?: boolean): Promise<any> {
1919
let args = settings.unitTest.unittestArgs.slice(0);
2020
if (runFailedTests === true) {
2121
testsToRun = { testFile: [], testFolder: [], testSuite: [], testFunction: [] };
22-
testsToRun.testFunction = tests.testFunctions.filter(fn=>{
22+
testsToRun.testFunction = tests.testFunctions.filter(fn => {
2323
return fn.testFunction.status === TestStatus.Error || fn.testFunction.status === TestStatus.Fail;
24-
}).map(fn=>fn.testFunction);
24+
}).map(fn => fn.testFunction);
2525
}
2626
return runTest(this.rootDirectory, tests, args, testsToRun, this.cancellationToken, this.outputChannel);
2727
}

0 commit comments

Comments
 (0)