@@ -6,7 +6,7 @@ import * as path from 'path';
66import * as net from 'net' ;
77import { IConfigurationService , ITestOutputChannel } from '../../../common/types' ;
88import { createDeferred , Deferred } from '../../../common/utils/async' ;
9- import { traceLog , traceVerbose } from '../../../logging' ;
9+ import { traceError , traceLog , traceVerbose } from '../../../logging' ;
1010import { DataReceivedEvent , ExecutionTestPayload , ITestExecutionAdapter , ITestServer } from '../common/types' ;
1111import {
1212 ExecutionFactoryCreateWithEnvironmentOptions ,
@@ -112,18 +112,16 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
112112 testArgs . splice ( 0 , 0 , '--rootdir' , uri . fsPath ) ;
113113 }
114114
115- // why is this needed?
116115 if ( debugBool && ! testArgs . some ( ( a ) => a . startsWith ( '--capture' ) || a === '-s' ) ) {
117116 testArgs . push ( '--capture' , 'no' ) ;
118117 }
119- const pluginArgs = [ '-p' , 'vscode_pytest' ] . concat ( testArgs ) . concat ( testIds ) ;
120- const scriptPath = path . join ( fullPluginPath , 'vscode_pytest' , 'run_pytest_script.py' ) ;
121- const runArgs = [ scriptPath , ...testArgs ] ;
122118
119+ // create payload with testIds to send to run pytest script
123120 const testData = JSON . stringify ( testIds ) ;
124121 const headers = [ `Content-Length: ${ Buffer . byteLength ( testData ) } ` , 'Content-Type: application/json' ] ;
125122 const payload = `${ headers . join ( '\r\n' ) } \r\n\r\n${ testData } ` ;
126123
124+ let pytestRunTestIdsPort : string | undefined ;
127125 const startServer = ( ) : Promise < number > =>
128126 new Promise ( ( resolve , reject ) => {
129127 const server = net . createServer ( ( socket : net . Socket ) => {
@@ -151,34 +149,40 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
151149 await startServer ( )
152150 . then ( ( assignedPort ) => {
153151 traceLog ( `Server started and listening on port ${ assignedPort } ` ) ;
152+ pytestRunTestIdsPort = assignedPort . toString ( ) ;
154153 if ( spawnOptions . extraVariables )
155- spawnOptions . extraVariables . RUN_TEST_IDS_PORT = assignedPort . toString ( ) ;
154+ spawnOptions . extraVariables . RUN_TEST_IDS_PORT = pytestRunTestIdsPort ;
156155 } )
157156 . catch ( ( error ) => {
158- console . error ( 'Error starting server:' , error ) ;
157+ traceError ( 'Error starting server:' , error ) ;
159158 } ) ;
160159
161160 if ( debugBool ) {
162161 const pytestPort = this . testServer . getPort ( ) . toString ( ) ;
163162 const pytestUUID = uuid . toString ( ) ;
164163 const launchOptions : LaunchOptions = {
165164 cwd : uri . fsPath ,
166- args : pluginArgs ,
165+ args : testArgs ,
167166 token : spawnOptions . token ,
168167 testProvider : PYTEST_PROVIDER ,
169168 pytestPort,
170169 pytestUUID,
170+ pytestRunTestIdsPort,
171171 } ;
172- console . debug ( `Running debug test with arguments: ${ pluginArgs . join ( ' ' ) } \r\n` ) ;
172+ traceVerbose ( `Running debug test with arguments: ${ testArgs . join ( ' ' ) } \r\n` ) ;
173173 await debugLauncher ! . launchDebugger ( launchOptions ) ;
174174 } else {
175+ // combine path to run script with run args
176+ const scriptPath = path . join ( fullPluginPath , 'vscode_pytest' , 'run_pytest_script.py' ) ;
177+ const runArgs = [ scriptPath , ...testArgs ] ;
178+
175179 await execService ?. exec ( runArgs , spawnOptions ) . catch ( ( ex ) => {
176- console . debug ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
180+ traceError ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
177181 return Promise . reject ( ex ) ;
178182 } ) ;
179183 }
180184 } catch ( ex ) {
181- console . debug ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
185+ traceVerbose ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
182186 return Promise . reject ( ex ) ;
183187 }
184188
0 commit comments