@@ -12,11 +12,13 @@ import {
1212 IPythonExecutionFactory ,
1313 SpawnOptions ,
1414} from '../../../common/process/types' ;
15- import { EXTENSION_ROOT_DIR } from '../../../constants' ;
1615import { 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' ;
1719
1820// 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;
2022/**
2123 * Wrapper Class for pytest test execution. This is where we call `runTestCommand`?
2224 */
@@ -47,11 +49,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
4749 testIds : string [ ] ,
4850 debugBool ?: boolean ,
4951 executionFactory ?: IPythonExecutionFactory ,
52+ debugLauncher ?: ITestDebugLauncher ,
5053 ) : Promise < ExecutionTestPayload > {
5154 traceVerbose ( uri , testIds , debugBool ) ;
5255 if ( executionFactory !== undefined ) {
5356 // ** new version of run tests.
54- return this . runTestsNew ( uri , testIds , debugBool , executionFactory ) ;
57+ return this . runTestsNew ( uri , testIds , debugBool , executionFactory , debugLauncher ) ;
5558 }
5659 // if executionFactory is undefined, we are using the old method signature of run tests.
5760 this . outputChannel . appendLine ( 'Running tests.' ) ;
@@ -64,6 +67,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
6467 testIds : string [ ] ,
6568 debugBool ?: boolean ,
6669 executionFactory ?: IPythonExecutionFactory ,
70+ debugLauncher ?: ITestDebugLauncher ,
6771 ) : Promise < ExecutionTestPayload > {
6872 const deferred = createDeferred < ExecutionTestPayload > ( ) ;
6973 const relativePathToPytest = 'pythonFiles' ;
@@ -106,16 +110,29 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
106110 testArgs . splice ( 0 , 0 , '--rootdir' , uri . fsPath ) ;
107111 }
108112
113+ // why is this needed?
109114 if ( debugBool && ! testArgs . some ( ( a ) => a . startsWith ( '--capture' ) || a === '-s' ) ) {
110115 testArgs . push ( '--capture' , 'no' ) ;
111116 }
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+ }
119136 } catch ( ex ) {
120137 console . debug ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
121138 return Promise . reject ( ex ) ;
0 commit comments