2
2
// Licensed under the MIT License.
3
3
4
4
import { Uri } from 'vscode' ;
5
- import path from 'path' ;
5
+ import * as path from 'path' ;
6
6
import { IConfigurationService , ITestOutputChannel } from '../../../common/types' ;
7
7
import { createDeferred , Deferred } from '../../../common/utils/async' ;
8
8
import { traceVerbose } from '../../../logging' ;
@@ -13,7 +13,10 @@ import {
13
13
SpawnOptions ,
14
14
} from '../../../common/process/types' ;
15
15
import { EXTENSION_ROOT_DIR } from '../../../constants' ;
16
+ import { removePositionalFoldersAndFiles } from './arguments' ;
16
17
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ ( global as any ) . EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR ;
17
20
/**
18
21
* Wrapper Class for pytest test execution. This is where we call `runTestCommand`?
19
22
*/
@@ -93,12 +96,29 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
93
96
// need to check what will happen in the exec service is NOT defined and is null
94
97
const execService = await executionFactory ?. createActivatedEnvironment ( creationOptions ) ;
95
98
96
- const testIdsString = testIds . join ( ' ' ) ;
97
- console . debug ( 'what to do with debug bool?' , debugBool ) ;
98
99
try {
99
- execService ?. exec ( [ '-m' , 'pytest' , '-p' , 'vscode_pytest' , testIdsString ] . concat ( pytestArgs ) , spawnOptions ) ;
100
+ // Remove positional test folders and files, we will add as needed per node
101
+ const testArgs = removePositionalFoldersAndFiles ( pytestArgs ) ;
102
+
103
+ // if user has provided `--rootdir` then use that, otherwise add `cwd`
104
+ if ( testArgs . filter ( ( a ) => a . startsWith ( '--rootdir' ) ) . length === 0 ) {
105
+ // Make sure root dir is set so pytest can find the relative paths
106
+ testArgs . splice ( 0 , 0 , '--rootdir' , uri . fsPath ) ;
107
+ }
108
+
109
+ if ( debugBool && ! testArgs . some ( ( a ) => a . startsWith ( '--capture' ) || a === '-s' ) ) {
110
+ testArgs . push ( '--capture' , 'no' ) ;
111
+ }
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 ) ;
100
119
} catch ( ex ) {
101
- console . error ( ex ) ;
120
+ console . debug ( `Error while running tests: ${ testIds } \r\n${ ex } \r\n\r\n` ) ;
121
+ return Promise . reject ( ex ) ;
102
122
}
103
123
104
124
return deferred . promise ;
0 commit comments