@@ -12,11 +12,13 @@ import {
12
12
IPythonExecutionFactory ,
13
13
SpawnOptions ,
14
14
} from '../../../common/process/types' ;
15
- import { EXTENSION_ROOT_DIR } from '../../../constants' ;
16
15
import { removePositionalFoldersAndFiles } from './arguments' ;
16
+ import { ITestDebugLauncher , LaunchOptions } from '../../common/types' ;
17
+ import { PYTEST_PROVIDER } from '../../common/constants' ;
18
+ import { EXTENSION_ROOT_DIR } from '../../../common/constants' ;
17
19
18
20
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- ( global as any ) . EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR ;
21
+ // (global as any).EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR;
20
22
/**
21
23
* Wrapper Class for pytest test execution. This is where we call `runTestCommand`?
22
24
*/
@@ -47,11 +49,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
47
49
testIds : string [ ] ,
48
50
debugBool ?: boolean ,
49
51
executionFactory ?: IPythonExecutionFactory ,
52
+ debugLauncher ?: ITestDebugLauncher ,
50
53
) : Promise < ExecutionTestPayload > {
51
54
traceVerbose ( uri , testIds , debugBool ) ;
52
55
if ( executionFactory !== undefined ) {
53
56
// ** new version of run tests.
54
- return this . runTestsNew ( uri , testIds , debugBool , executionFactory ) ;
57
+ return this . runTestsNew ( uri , testIds , debugBool , executionFactory , debugLauncher ) ;
55
58
}
56
59
// if executionFactory is undefined, we are using the old method signature of run tests.
57
60
this . outputChannel . appendLine ( 'Running tests.' ) ;
@@ -64,6 +67,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
64
67
testIds : string [ ] ,
65
68
debugBool ?: boolean ,
66
69
executionFactory ?: IPythonExecutionFactory ,
70
+ debugLauncher ?: ITestDebugLauncher ,
67
71
) : Promise < ExecutionTestPayload > {
68
72
const deferred = createDeferred < ExecutionTestPayload > ( ) ;
69
73
const relativePathToPytest = 'pythonFiles' ;
@@ -106,16 +110,29 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
106
110
testArgs . splice ( 0 , 0 , '--rootdir' , uri . fsPath ) ;
107
111
}
108
112
113
+ // why is this needed?
109
114
if ( debugBool && ! testArgs . some ( ( a ) => a . startsWith ( '--capture' ) || a === '-s' ) ) {
110
115
testArgs . push ( '--capture' , 'no' ) ;
111
116
}
112
-
113
- console . debug ( `Running test with arguments: ${ testArgs . join ( ' ' ) } \r\n` ) ;
114
- console . debug ( `Current working directory: ${ uri . fsPath } \r\n` ) ;
115
-
116
- const argArray = [ '-m' , 'pytest' , '-p' , 'vscode_pytest' ] . concat ( testArgs ) . concat ( testIds ) ;
117
- console . debug ( 'argArray' , argArray ) ;
118
- execService ?. exec ( argArray , spawnOptions ) ;
117
+ const pluginArgs = [ '-p' , 'vscode_pytest' , '-v' ] . concat ( testArgs ) . concat ( testIds ) ;
118
+ if ( debugBool ) {
119
+ const pytestPort = this . testServer . getPort ( ) . toString ( ) ;
120
+ const pytestUUID = uuid . toString ( ) ;
121
+ const launchOptions : LaunchOptions = {
122
+ cwd : uri . fsPath ,
123
+ args : pluginArgs ,
124
+ token : spawnOptions . token ,
125
+ testProvider : PYTEST_PROVIDER ,
126
+ pytestPort,
127
+ pytestUUID,
128
+ } ;
129
+ console . debug ( `Running debug test with arguments: ${ pluginArgs . join ( ' ' ) } \r\n` ) ;
130
+ await debugLauncher ! . launchDebugger ( launchOptions ) ;
131
+ } else {
132
+ const runArgs = [ '-m' , 'pytest' ] . concat ( pluginArgs ) ;
133
+ console . debug ( `Running test with arguments: ${ runArgs . join ( ' ' ) } \r\n` ) ;
134
+ execService ?. exec ( runArgs , spawnOptions ) ;
135
+ }
119
136
} catch ( ex ) {
120
137
console . debug ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
121
138
return Promise . reject ( ex ) ;
0 commit comments