|
1 | 1 | 'use strict'; |
2 | 2 | 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'; |
4 | 4 | import * as nosetests from './nosetest/main'; |
5 | 5 | import * as pytest from './pytest/main'; |
6 | 6 | 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'; |
12 | 12 | import * as fs from 'fs'; |
13 | 13 | import * as path from 'path'; |
14 | 14 | import * as constants from '../common/constants'; |
15 | | -import {activateCodeLenses} from './codeLenses/main'; |
| 15 | +import { activateCodeLenses } from './codeLenses/main'; |
| 16 | +import { Product } from '../common/installer'; |
16 | 17 |
|
17 | 18 | const settings = PythonSettings.getInstance(); |
18 | 19 | let testManager: BaseTestManager; |
@@ -151,12 +152,41 @@ function onConfigChanged() { |
151 | 152 | // No need to display errors |
152 | 153 | discoverTests(true, true); |
153 | 154 | } |
| 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 | +} |
154 | 179 | function displayTestFrameworkError() { |
155 | 180 | 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."); |
157 | 182 | } |
158 | 183 | 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 | + }); |
160 | 190 | } |
161 | 191 | return null; |
162 | 192 | } |
|
0 commit comments