Skip to content

Commit 118eaa6

Browse files
committed
testController: Use a per-project terminal to run tests
To run tests from tox.ini files from different projects, create (and re-use) separate terminals. Terminal identifier uses label and description of root test item (the tox.ini).
1 parent 64376b8 commit 118eaa6

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/testController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import * as path from 'path';
33
import * as util from 'util';
44
import { runTox, getToxEnvs } from './run';
5+
import { getTerminal, getRootParentLabelDesc } from './utils';
56

67
export function create() {
78
const controller = vscode.tests.createTestController('toxTestController', 'Tox Testing');
@@ -38,7 +39,7 @@ export function create() {
3839
const start = Date.now();
3940
try {
4041
const cwd = vscode.workspace.getWorkspaceFolder(test.uri!)!.uri.path;
41-
runTox([test.label], cwd);
42+
runTox([test.label], "", getTerminal(cwd, getRootParentLabelDesc(test)));
4243
run.passed(test, Date.now() - start);
4344
}
4445
catch (e: any) {

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ export function getTerminal(projDir : string = findProjectDir(), name : string =
3434
}
3535
return vscode.window.createTerminal({"cwd": projDir, "name": name});
3636
}
37+
38+
/**
39+
* Get the top-most parent label (+ description) for terminal name
40+
* @param test The test to start from.
41+
* @returns The label and description of the root test item.
42+
*/
43+
export function getRootParentLabelDesc(test: vscode.TestItem) : string {
44+
let root = test;
45+
46+
while (root.parent !== undefined){
47+
root = root.parent;
48+
}
49+
50+
return root.label + " " + root.description; // FIXME: return as tuple?
51+
}

0 commit comments

Comments
 (0)