Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63b85de

Browse files
authored
Merge pull request DonJayamanne#164 from aschlapsi/master
Added support for pytest as unit test option
2 parents 91d7dcd + 5b3cd6e commit 63b85de

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,16 @@
446446
"default": "nosetests",
447447
"description": "Path to nosetests, you can use a custom version of nosetests by modifying this setting to include the full path."
448448
},
449+
"python.unitTest.pyTestEnabled": {
450+
"type": "boolean",
451+
"default": false,
452+
"description": "Whether to enable or disable unit testing using pytest."
453+
},
454+
"python.unitTest.pyTestPath": {
455+
"type": "string",
456+
"default": "pytest",
457+
"description": "Path to pytest, you can use a custom version of pytest by modifying this setting to include the full path."
458+
},
449459
"python.unitTest.unittestEnabled": {
450460
"type": "boolean",
451461
"default": true,

src/client/common/configSettings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface IPythonSettings {
1414
export interface IUnitTestSettings {
1515
nosetestsEnabled: boolean;
1616
nosetestPath: string;
17+
pyTestEnabled: boolean;
18+
pyTestPath: string;
1719
unittestEnabled: boolean;
1820
outputWindow: string;
1921
}

src/client/providers/testprovider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as vscode from "vscode";
33
import * as baseTest from "./../unittest/baseTestRunner";
44
import * as unittest from "./../unittest/unittest";
55
import * as nosetest from "./../unittest/nosetests";
6+
import * as pytest from "./../unittest/pytest";
67
import * as settings from "./../common/configSettings";
78
import * as telemetryHelper from "../common/telemetry";
89
import * as telemetryContracts from "../common/telemetryContracts";
@@ -16,6 +17,7 @@ export function activateUnitTestProvider(context: vscode.ExtensionContext, setti
1617

1718
testProviders.push(new unittest.PythonUnitTest(settings, outputChannel));
1819
testProviders.push(new nosetest.NoseTests(settings, outputChannel));
20+
testProviders.push(new pytest.PyTestTests(settings, outputChannel));
1921
}
2022

2123
function runUnitTests(filePath: string = "") {

src/client/unittest/pytest.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
import * as baseTestRunner from "./baseTestRunner";
4+
import * as settings from "./../common/configSettings";
5+
import {OutputChannel} from "vscode";
6+
7+
export class PyTestTests extends baseTestRunner.BaseTestRunner {
8+
constructor(pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel) {
9+
super("pytest", pythonSettings, outputChannel, true);
10+
}
11+
12+
public isEnabled(): boolean {
13+
return this.pythonSettings.unitTest.pyTestEnabled;
14+
}
15+
16+
public runTests(filePath: string = ""): Promise<any> {
17+
if (!this.pythonSettings.unitTest.pyTestEnabled) {
18+
return Promise.resolve();
19+
}
20+
21+
let pyTestPath = this.pythonSettings.unitTest.pyTestPath;
22+
let cmdLine = `${pyTestPath} ${filePath}`;
23+
return new Promise<any>(resolve => {
24+
this.run(cmdLine).then(messages => {
25+
resolve(messages);
26+
});
27+
});
28+
}
29+
}

0 commit comments

Comments
 (0)