Skip to content

Commit 095e9ab

Browse files
committed
check if config exists #459
1 parent 3f70976 commit 095e9ab

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

src/client/unittests/pytest/testConfigurationManager.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as vscode from 'vscode';
22
import { TestConfigurationManager } from '../common/testConfigurationManager';
3+
import * as fs from 'fs';
4+
import * as path from 'path';
35

46
export class ConfigurationManager extends TestConfigurationManager {
57
public enable(): Thenable<any> {
@@ -11,15 +13,36 @@ export class ConfigurationManager extends TestConfigurationManager {
1113
return pythonConfig.update('unitTest.pyTestEnabled', false);
1214
}
1315

16+
private static configFilesExist(rootDir: string): Promise<boolean> {
17+
const promises = [
18+
new Promise<boolean>(resolve => {
19+
fs.exists(path.join(rootDir, 'pytest.ini'), exists => { resolve(true); });
20+
}),
21+
new Promise<boolean>(resolve => {
22+
fs.exists(path.join(rootDir, 'tox.ini'), exists => { resolve(true); });
23+
}),
24+
new Promise<boolean>(resolve => {
25+
fs.exists(path.join(rootDir, 'setup.cfg'), exists => { resolve(true); });
26+
})];
27+
return Promise.all(promises).then(values => {
28+
return values.some(exists => exists);
29+
});
30+
}
1431
public configure(rootDir: string): Promise<any> {
1532
const args = [];
1633
const configFileOptionLabel = 'Use existing config file';
17-
return this.getTestDirs(rootDir).then(subDirs => {
18-
const rootConfigFileOption = <vscode.QuickPickItem>{
19-
label: configFileOptionLabel,
20-
description: 'pytest.ini, tox.ini or setup.cfg'
21-
};
22-
return this.selectTestDir(rootDir, subDirs, [rootConfigFileOption]);
34+
const options: vscode.QuickPickItem[] = [];
35+
return ConfigurationManager.configFilesExist(rootDir).then(configExists => {
36+
if (configExists) {
37+
options.push({
38+
label: configFileOptionLabel,
39+
description: 'pytest.ini, tox.ini or setup.cfg'
40+
});
41+
}
42+
}).then(() => {
43+
return this.getTestDirs(rootDir);
44+
}).then(subDirs => {
45+
return this.selectTestDir(rootDir, subDirs, options);
2346
}).then(testDir => {
2447
if (typeof testDir === 'string' && testDir !== configFileOptionLabel) {
2548
args.push(testDir);

0 commit comments

Comments
 (0)