Skip to content

Commit 9faa494

Browse files
committed
prompt to enable a test framework (fix #448)
1 parent 4c7503f commit 9faa494

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

‎src/client/unittests/main.ts‎

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
'use strict';
22
import * as vscode from 'vscode';
3-
import {Tests, TestsToRun, TestFolder, TestFile, TestStatus, TestSuite, TestFunction, FlattenedTestFunction, CANCELLATION_REASON} from './common/contracts';
3+
import { Tests, TestsToRun, TestFolder, TestFile, TestStatus, TestSuite, TestFunction, FlattenedTestFunction, CANCELLATION_REASON } from './common/contracts';
44
import * as nosetests from './nosetest/main';
55
import * as pytest from './pytest/main';
66
import * as unittest from './unittest/main';
7-
import {resolveValueAsTestToRun, getDiscoveredTests} from './common/testUtils';
8-
import {BaseTestManager} from './common/baseTestManager';
9-
import {PythonSettings, IUnitTestSettings} from '../common/configSettings';
10-
import {TestResultDisplay} from './display/main';
11-
import {TestDisplay} from './display/picker';
7+
import { resolveValueAsTestToRun, getDiscoveredTests } from './common/testUtils';
8+
import { BaseTestManager } from './common/baseTestManager';
9+
import { PythonSettings, IUnitTestSettings } from '../common/configSettings';
10+
import { TestResultDisplay } from './display/main';
11+
import { TestDisplay } from './display/picker';
1212
import * as fs from 'fs';
1313
import * as path from 'path';
1414
import * as constants from '../common/constants';
15-
import {activateCodeLenses} from './codeLenses/main';
15+
import { activateCodeLenses } from './codeLenses/main';
16+
import { Product } from '../common/installer';
1617

1718
const settings = PythonSettings.getInstance();
1819
let testManager: BaseTestManager;
@@ -151,12 +152,41 @@ function onConfigChanged() {
151152
// No need to display errors
152153
discoverTests(true, true);
153154
}
155+
function promptToEnableTestFramework() {
156+
const items = [{
157+
label: 'unittest', settingToEnable: 'unitTest.unittestEnabled',
158+
description: 'Standard Python test framework',
159+
detail: 'https://docs.python.org/2/library/unittest.html'
160+
},
161+
{
162+
label: 'pytest', settingToEnable: 'unitTest.pyTestEnabled',
163+
description: 'Can run unittest (including trial) and nose test suites out of the box',
164+
detail: 'http://docs.pytest.org/en/latest/'
165+
},
166+
{
167+
label: 'nose', settingToEnable: 'unitTest.nosetestsEnabled',
168+
description: 'nose framework',
169+
detail: 'https://docs.python.org/2/library/unittest.html'
170+
}];
171+
vscode.window.showQuickPick(items, { matchOnDescription: true, matchOnDetail: true, placeHolder: 'Select a test framework/tool to enable' }).then(item => {
172+
if (!item) {
173+
return;
174+
}
175+
const pythonConfig = vscode.workspace.getConfiguration('python');
176+
pythonConfig.update(item.settingToEnable, true);
177+
});
178+
}
154179
function displayTestFrameworkError() {
155180
if (settings.unitTest.pyTestEnabled && settings.unitTest.nosetestsEnabled && settings.unitTest.unittestEnabled) {
156-
vscode.window.showErrorMessage("Enable only one of the test frameworks (nosetest or pytest), not both.")
181+
vscode.window.showErrorMessage("Enable only one of the test frameworks (nosetest or pytest), not both.");
157182
}
158183
else {
159-
vscode.window.showInformationMessage('Please enable one of the test frameworks (unittest, pytest or nosetest)');
184+
const option = 'Enable a Test Framework/Tool';
185+
vscode.window.showInformationMessage('Please enable one of the test frameworks (unittest, pytest or nosetest)', option).then(item => {
186+
if (item === option) {
187+
promptToEnableTestFramework();
188+
}
189+
});
160190
}
161191
return null;
162192
}

0 commit comments

Comments
 (0)