3
3
4
4
import { TestRun , Uri } from 'vscode' ;
5
5
import * as path from 'path' ;
6
- import * as net from 'net' ;
7
6
import { IConfigurationService , ITestOutputChannel } from '../../../common/types' ;
8
7
import { createDeferred , Deferred } from '../../../common/utils/async' ;
9
8
import { traceError , traceInfo , traceLog , traceVerbose } from '../../../logging' ;
@@ -23,6 +22,7 @@ import { removePositionalFoldersAndFiles } from './arguments';
23
22
import { ITestDebugLauncher , LaunchOptions } from '../../common/types' ;
24
23
import { PYTEST_PROVIDER } from '../../common/constants' ;
25
24
import { EXTENSION_ROOT_DIR } from '../../../common/constants' ;
25
+ import { startTestIdServer } from '../common/utils' ;
26
26
27
27
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28
28
// (global as any).EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR;
@@ -116,40 +116,10 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
116
116
if ( debugBool && ! testArgs . some ( ( a ) => a . startsWith ( '--capture' ) || a === '-s' ) ) {
117
117
testArgs . push ( '--capture' , 'no' ) ;
118
118
}
119
-
120
- // create payload with testIds to send to run pytest script
121
- const testData = JSON . stringify ( testIds ) ;
122
- const headers = [ `Content-Length: ${ Buffer . byteLength ( testData ) } ` , 'Content-Type: application/json' ] ;
123
- const payload = `${ headers . join ( '\r\n' ) } \r\n\r\n${ testData } ` ;
124
- traceLog ( `Running pytest execution for the following test ids: ${ testIds } ` ) ;
119
+ traceLog ( `Running PYTEST execution for the following test ids: ${ testIds } ` ) ;
125
120
126
121
let pytestRunTestIdsPort : string | undefined ;
127
- const startServer = ( ) : Promise < number > =>
128
- new Promise ( ( resolve , reject ) => {
129
- const server = net . createServer ( ( socket : net . Socket ) => {
130
- socket . on ( 'end' , ( ) => {
131
- traceVerbose ( 'Client disconnected for pytest test ids server' ) ;
132
- } ) ;
133
- } ) ;
134
-
135
- server . listen ( 0 , ( ) => {
136
- const { port } = server . address ( ) as net . AddressInfo ;
137
- traceVerbose ( `Server listening on port ${ port } for pytest test ids server` ) ;
138
- resolve ( port ) ;
139
- } ) ;
140
-
141
- server . on ( 'error' , ( error : Error ) => {
142
- traceError ( 'Error starting server for pytest test ids server:' , error ) ;
143
- reject ( error ) ;
144
- } ) ;
145
- server . on ( 'connection' , ( socket : net . Socket ) => {
146
- socket . write ( payload ) ;
147
- traceVerbose ( 'payload sent for pytest execution' , payload ) ;
148
- } ) ;
149
- } ) ;
150
-
151
- // Start the server and wait until it is listening
152
- await startServer ( )
122
+ await startTestIdServer ( testIds )
153
123
. then ( ( assignedPort ) => {
154
124
traceVerbose ( `Server started for pytest test ids server and listening on port ${ assignedPort } ` ) ;
155
125
pytestRunTestIdsPort = assignedPort . toString ( ) ;
0 commit comments