@@ -15,7 +15,6 @@ import {
15
15
} from '../common/types' ;
16
16
import {
17
17
ExecutionFactoryCreateWithEnvironmentOptions ,
18
- ExecutionResult ,
19
18
IPythonExecutionFactory ,
20
19
SpawnOptions ,
21
20
} from '../../../common/process/types' ;
@@ -25,6 +24,12 @@ import { PYTEST_PROVIDER } from '../../common/constants';
25
24
import { EXTENSION_ROOT_DIR } from '../../../common/constants' ;
26
25
import { startTestIdServer } from '../common/utils' ;
27
26
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ // (global as any).EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR;
29
+ /**
30
+ * Wrapper Class for pytest test execution..
31
+ */
32
+
28
33
export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
29
34
constructor (
30
35
public testServer : ITestServer ,
@@ -43,20 +48,18 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
43
48
) : Promise < ExecutionTestPayload > {
44
49
const uuid = this . testServer . createUUID ( uri . fsPath ) ;
45
50
traceVerbose ( uri , testIds , debugBool ) ;
46
- const disposedDataReceived = this . testServer . onRunDataReceived ( ( e : DataReceivedEvent ) => {
51
+ const disposable = this . testServer . onRunDataReceived ( ( e : DataReceivedEvent ) => {
47
52
if ( runInstance ) {
48
53
this . resultResolver ?. resolveExecution ( JSON . parse ( e . data ) , runInstance ) ;
49
54
}
50
55
} ) ;
51
- const dispose = function ( testServer : ITestServer ) {
52
- testServer . deleteUUID ( uuid ) ;
53
- disposedDataReceived . dispose ( ) ;
54
- } ;
55
- runInstance ?. token . onCancellationRequested ( ( ) => {
56
- dispose ( this . testServer ) ;
57
- } ) ;
58
- await this . runTestsNew ( uri , testIds , uuid , runInstance , debugBool , executionFactory , debugLauncher ) ;
59
-
56
+ try {
57
+ await this . runTestsNew ( uri , testIds , uuid , debugBool , executionFactory , debugLauncher ) ;
58
+ } finally {
59
+ this . testServer . deleteUUID ( uuid ) ;
60
+ disposable . dispose ( ) ;
61
+ // confirm with testing that this gets called (it must clean this up)
62
+ }
60
63
// placeholder until after the rewrite is adopted
61
64
// TODO: remove after adoption.
62
65
const executionPayload : ExecutionTestPayload = {
@@ -71,7 +74,6 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
71
74
uri : Uri ,
72
75
testIds : string [ ] ,
73
76
uuid : string ,
74
- runInstance ?: TestRun ,
75
77
debugBool ?: boolean ,
76
78
executionFactory ?: IPythonExecutionFactory ,
77
79
debugLauncher ?: ITestDebugLauncher ,
@@ -141,27 +143,14 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
141
143
traceInfo ( `Running DEBUG pytest with arguments: ${ testArgs . join ( ' ' ) } \r\n` ) ;
142
144
await debugLauncher ! . launchDebugger ( launchOptions , ( ) => {
143
145
deferred . resolve ( ) ;
144
- this . testServer . deleteUUID ( uuid ) ;
145
146
} ) ;
146
147
} else {
147
148
// combine path to run script with run args
148
149
const scriptPath = path . join ( fullPluginPath , 'vscode_pytest' , 'run_pytest_script.py' ) ;
149
150
const runArgs = [ scriptPath , ...testArgs ] ;
150
151
traceInfo ( `Running pytests with arguments: ${ runArgs . join ( ' ' ) } \r\n` ) ;
151
152
152
- const deferredExec = createDeferred < ExecutionResult < string > > ( ) ;
153
- const result = execService ?. execObservable ( runArgs , spawnOptions ) ;
154
-
155
- runInstance ?. token . onCancellationRequested ( ( ) => {
156
- result ?. proc ?. kill ( ) ;
157
- } ) ;
158
-
159
- result ?. proc ?. on ( 'close' , ( ) => {
160
- deferredExec . resolve ( { stdout : '' , stderr : '' } ) ;
161
- this . testServer . deleteUUID ( uuid ) ;
162
- deferred . resolve ( ) ;
163
- } ) ;
164
- await deferredExec . promise ;
153
+ await execService ?. exec ( runArgs , spawnOptions ) ;
165
154
}
166
155
} catch ( ex ) {
167
156
traceError ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
0 commit comments