@@ -162,83 +162,7 @@ suite('End to End Tests: unittest adapters', () => {
162162 traceLog ( 'Symlink was not found to remove after tests, exiting successfully, nestedSymlink.' ) ;
163163 }
164164 } ) ;
165- test ( 'unittest execution adapter RuntimeError handling' , async ( ) => {
166- resultResolver = new PythonResultResolver ( testController , unittestProvider , workspaceUri ) ;
167- let callCount = 0 ;
168- let failureOccurred = false ;
169- let failureMsg = '' ;
170- resultResolver . _resolveExecution = async ( data , _token ?) => {
171- // do the following asserts for each time resolveExecution is called, should be called once per test.
172- callCount = callCount + 1 ;
173- traceLog ( `unittest execution adapter seg fault error handling \n ${ JSON . stringify ( data ) } ` ) ;
174- try {
175- if ( data . status === 'error' ) {
176- if ( data . error === undefined ) {
177- // Dereference a NULL pointer
178- const indexOfTest = JSON . stringify ( data ) . search ( 'RuntimeError' ) ;
179- if ( indexOfTest === - 1 ) {
180- failureOccurred = true ;
181- failureMsg = 'Expected test to have a RuntimeError' ;
182- }
183- } else if ( data . error . length === 0 ) {
184- failureOccurred = true ;
185- failureMsg = "Expected errors in 'error' field" ;
186- }
187- } else {
188- const indexOfTest = JSON . stringify ( data . result ) . search ( 'error' ) ;
189- if ( indexOfTest === - 1 ) {
190- failureOccurred = true ;
191- failureMsg =
192- 'If payload status is not error then the individual tests should be marked as errors. This should occur on windows machines.' ;
193- }
194- }
195- if ( data . result === undefined ) {
196- failureOccurred = true ;
197- failureMsg = 'Expected results to be present' ;
198- }
199- // make sure the testID is found in the results
200- const indexOfTest = JSON . stringify ( data ) . search ( 'test_runtime_error.TestRuntimeError.test_exception' ) ;
201- if ( indexOfTest === - 1 ) {
202- failureOccurred = true ;
203- failureMsg = 'Expected testId to be present' ;
204- }
205- } catch ( err ) {
206- failureMsg = err ? ( err as Error ) . toString ( ) : '' ;
207- failureOccurred = true ;
208- }
209- return Promise . resolve ( ) ;
210- } ;
211-
212- const testId = 'test_runtime_error.TestRuntimeError.test_exception' ;
213- const testIds : string [ ] = [ testId ] ;
214165
215- // set workspace to test workspace folder
216- workspaceUri = Uri . parse ( rootPathErrorWorkspace ) ;
217- configService . getSettings ( workspaceUri ) . testing . unittestArgs = [ '-s' , '.' , '-p' , '*test*.py' ] ;
218-
219- // run pytest execution
220- const executionAdapter = new UnittestTestExecutionAdapter (
221- configService ,
222- testOutputChannel . object ,
223- resultResolver ,
224- envVarsService ,
225- ) ;
226- const testRun = typeMoq . Mock . ofType < TestRun > ( ) ;
227- testRun
228- . setup ( ( t ) => t . token )
229- . returns (
230- ( ) =>
231- ( {
232- onCancellationRequested : ( ) => undefined ,
233- } as any ) ,
234- ) ;
235- await executionAdapter
236- . runTests ( workspaceUri , testIds , TestRunProfileKind . Run , testRun . object , pythonExecFactory )
237- . finally ( ( ) => {
238- assert . strictEqual ( callCount , 1 , 'Expected _resolveExecution to be called once' ) ;
239- assert . strictEqual ( failureOccurred , false , failureMsg ) ;
240- } ) ;
241- } ) ;
242166 test ( 'unittest discovery adapter small workspace' , async ( ) => {
243167 // result resolver and saved data for assertions
244168 let actualData : {
@@ -595,4 +519,81 @@ suite('End to End Tests: unittest adapters', () => {
595519 assert . strictEqual ( failureOccurred , false , failureMsg ) ;
596520 } ) ;
597521 } ) ;
522+ test ( 'unittest execution adapter RuntimeError handling' , async ( ) => {
523+ resultResolver = new PythonResultResolver ( testController , unittestProvider , workspaceUri ) ;
524+ let callCount = 0 ;
525+ let failureOccurred = false ;
526+ let failureMsg = '' ;
527+ resultResolver . _resolveExecution = async ( data , _token ?) => {
528+ // do the following asserts for each time resolveExecution is called, should be called once per test.
529+ callCount = callCount + 1 ;
530+ traceLog ( `unittest execution adapter seg fault error handling \n ${ JSON . stringify ( data ) } ` ) ;
531+ try {
532+ if ( data . status === 'error' ) {
533+ if ( data . error === undefined ) {
534+ // Dereference a NULL pointer
535+ const indexOfTest = JSON . stringify ( data ) . search ( 'RuntimeError' ) ;
536+ if ( indexOfTest === - 1 ) {
537+ failureOccurred = true ;
538+ failureMsg = 'Expected test to have a RuntimeError' ;
539+ }
540+ } else if ( data . error . length === 0 ) {
541+ failureOccurred = true ;
542+ failureMsg = "Expected errors in 'error' field" ;
543+ }
544+ } else {
545+ const indexOfTest = JSON . stringify ( data . result ) . search ( 'error' ) ;
546+ if ( indexOfTest === - 1 ) {
547+ failureOccurred = true ;
548+ failureMsg =
549+ 'If payload status is not error then the individual tests should be marked as errors. This should occur on windows machines.' ;
550+ }
551+ }
552+ if ( data . result === undefined ) {
553+ failureOccurred = true ;
554+ failureMsg = 'Expected results to be present' ;
555+ }
556+ // make sure the testID is found in the results
557+ const indexOfTest = JSON . stringify ( data ) . search ( 'test_runtime_error.TestRuntimeError.test_exception' ) ;
558+ if ( indexOfTest === - 1 ) {
559+ failureOccurred = true ;
560+ failureMsg = 'Expected testId to be present' ;
561+ }
562+ } catch ( err ) {
563+ failureMsg = err ? ( err as Error ) . toString ( ) : '' ;
564+ failureOccurred = true ;
565+ }
566+ return Promise . resolve ( ) ;
567+ } ;
568+
569+ const testId = 'test_runtime_error.TestRuntimeError.test_exception' ;
570+ const testIds : string [ ] = [ testId ] ;
571+
572+ // set workspace to test workspace folder
573+ workspaceUri = Uri . parse ( rootPathErrorWorkspace ) ;
574+ configService . getSettings ( workspaceUri ) . testing . unittestArgs = [ '-s' , '.' , '-p' , '*test*.py' ] ;
575+
576+ // run pytest execution
577+ const executionAdapter = new UnittestTestExecutionAdapter (
578+ configService ,
579+ testOutputChannel . object ,
580+ resultResolver ,
581+ envVarsService ,
582+ ) ;
583+ const testRun = typeMoq . Mock . ofType < TestRun > ( ) ;
584+ testRun
585+ . setup ( ( t ) => t . token )
586+ . returns (
587+ ( ) =>
588+ ( {
589+ onCancellationRequested : ( ) => undefined ,
590+ } as any ) ,
591+ ) ;
592+ await executionAdapter
593+ . runTests ( workspaceUri , testIds , TestRunProfileKind . Run , testRun . object , pythonExecFactory )
594+ . finally ( ( ) => {
595+ assert . strictEqual ( callCount , 1 , 'Expected _resolveExecution to be called once' ) ;
596+ assert . strictEqual ( failureOccurred , false , failureMsg ) ;
597+ } ) ;
598+ } ) ;
598599} ) ;
0 commit comments