Skip to content

Commit b5b72d8

Browse files
Revert "Enable debug pytest (microsoft#21228)"
This reverts commit b0ebc9b.
1 parent 46bbe34 commit b5b72d8

File tree

8 files changed

+25
-80
lines changed

8 files changed

+25
-80
lines changed

.vscode/launch.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
// Enable this to log telemetry to the output during debugging
2323
"XVSC_PYTHON_LOG_TELEMETRY": "1",
2424
// Enable this to log debugger output. Directory must exist ahead of time
25-
"XDEBUGPY_LOG_DIR": "${workspaceRoot}/tmp/Debug_Output_Ex",
26-
"ENABLE_PYTHON_TESTING_REWRITE": "1"
25+
"XDEBUGPY_LOG_DIR": "${workspaceRoot}/tmp/Debug_Output_Ex"
2726
}
2827
},
2928
{

pythonFiles/vscode_pytest/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@ def pytest_sessionfinish(session, exitstatus):
179179
4: Pytest encountered an internal error or exception during test execution.
180180
5: Pytest was unable to find any tests to run.
181181
"""
182-
print(
183-
"pytest session has finished, exit status: ",
184-
exitstatus,
185-
"in discovery? ",
186-
IS_DISCOVERY,
187-
)
188182
cwd = pathlib.Path.cwd()
189183
if IS_DISCOVERY:
190184
try:
@@ -215,6 +209,7 @@ def pytest_sessionfinish(session, exitstatus):
215209
f"Pytest exited with error status: {exitstatus}, {ERROR_MESSAGE_CONST[exitstatus]}"
216210
)
217211
exitstatus_bool = "error"
212+
218213
execution_post(
219214
os.fsdecode(cwd),
220215
exitstatus_bool,

src/client/testing/common/debugLauncher.ts

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { ITestDebugLauncher, LaunchOptions } from './types';
1515
import { getConfigurationsForWorkspace } from '../../debugger/extension/configuration/launch.json/launchJsonReader';
1616
import { getWorkspaceFolder, getWorkspaceFolders } from '../../common/vscodeApis/workspaceApis';
1717
import { showErrorMessage } from '../../common/vscodeApis/windowApis';
18-
import { createDeferred } from '../../common/utils/async';
1918

2019
@injectable()
2120
export class DebugLauncher implements ITestDebugLauncher {
@@ -43,12 +42,16 @@ export class DebugLauncher implements ITestDebugLauncher {
4342
);
4443
const debugManager = this.serviceContainer.get<IDebugService>(IDebugService);
4544

46-
const deferred = createDeferred<void>();
47-
debugManager.onDidTerminateDebugSession(() => {
48-
deferred.resolve();
49-
});
50-
debugManager.startDebugging(workspaceFolder, launchArgs);
51-
return deferred.promise;
45+
return debugManager.startDebugging(workspaceFolder, launchArgs).then(
46+
// Wait for debug session to be complete.
47+
() =>
48+
new Promise<void>((resolve) => {
49+
debugManager.onDidTerminateDebugSession(() => {
50+
resolve();
51+
});
52+
}),
53+
(ex) => traceError('Failed to start debugging tests', ex),
54+
);
5255
}
5356

5457
private static resolveWorkspaceFolder(cwd: string): WorkspaceFolder {
@@ -178,12 +181,6 @@ export class DebugLauncher implements ITestDebugLauncher {
178181
const args = script(testArgs);
179182
const [program] = args;
180183
configArgs.program = program;
181-
// if the test provider is pytest, then use the pytest module instead of using a program
182-
const rewriteTestingEnabled = process.env.ENABLE_PYTHON_TESTING_REWRITE;
183-
if (options.testProvider === 'pytest' && rewriteTestingEnabled) {
184-
configArgs.module = 'pytest';
185-
configArgs.program = undefined;
186-
}
187184
configArgs.args = args.slice(1);
188185
// We leave configArgs.request as "test" so it will be sent in telemetry.
189186

@@ -204,21 +201,6 @@ export class DebugLauncher implements ITestDebugLauncher {
204201
throw Error(`Invalid debug config "${debugConfig.name}"`);
205202
}
206203
launchArgs.request = 'launch';
207-
if (options.testProvider === 'pytest' && rewriteTestingEnabled) {
208-
if (options.pytestPort && options.pytestUUID) {
209-
launchArgs.env = {
210-
...launchArgs.env,
211-
TEST_PORT: options.pytestPort,
212-
TEST_UUID: options.pytestUUID,
213-
};
214-
} else {
215-
throw Error(
216-
`Missing value for debug setup, both port and uuid need to be defined. port: "${options.pytestPort}" uuid: "${options.pytestUUID}"`,
217-
);
218-
}
219-
const pluginPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
220-
launchArgs.env.PYTHONPATH = pluginPath;
221-
}
222204

223205
// Clear out purpose so we can detect if the configuration was used to
224206
// run via F5 style debugging.
@@ -228,19 +210,13 @@ export class DebugLauncher implements ITestDebugLauncher {
228210
}
229211

230212
private static getTestLauncherScript(testProvider: TestProvider) {
231-
const rewriteTestingEnabled = process.env.ENABLE_PYTHON_TESTING_REWRITE;
232213
switch (testProvider) {
233214
case 'unittest': {
234-
if (rewriteTestingEnabled) {
235-
return internalScripts.execution_py_testlauncher; // this is the new way to run unittest execution, debugger
236-
}
237215
return internalScripts.visualstudio_py_testlauncher; // old way unittest execution, debugger
216+
// return internalScripts.execution_py_testlauncher; // this is the new way to run unittest execution, debugger
238217
}
239218
case 'pytest': {
240-
if (rewriteTestingEnabled) {
241-
return (testArgs: string[]) => testArgs;
242-
}
243-
return internalScripts.testlauncher; // old way pytest execution, debugger
219+
return internalScripts.testlauncher;
244220
}
245221
default: {
246222
throw new Error(`Unknown test provider '${testProvider}'`);

src/client/testing/common/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export type LaunchOptions = {
2525
testProvider: TestProvider;
2626
token?: CancellationToken;
2727
outChannel?: OutputChannel;
28-
pytestPort?: string;
29-
pytestUUID?: string;
3028
};
3129

3230
export type ParserOptions = TestDiscoveryOptions;

src/client/testing/testController/common/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Uri,
1313
WorkspaceFolder,
1414
} from 'vscode';
15-
import { ITestDebugLauncher, TestDiscoveryOptions } from '../../common/types';
15+
import { TestDiscoveryOptions } from '../../common/types';
1616
import { IPythonExecutionFactory } from '../../../common/process/types';
1717

1818
export type TestRunInstanceOptions = TestRunOptions & {
@@ -193,7 +193,6 @@ export interface ITestExecutionAdapter {
193193
testIds: string[],
194194
debugBool?: boolean,
195195
executionFactory?: IPythonExecutionFactory,
196-
debugLauncher?: ITestDebugLauncher,
197196
): Promise<ExecutionTestPayload>;
198197
}
199198

src/client/testing/testController/controller.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
409409
token,
410410
request.profile?.kind === TestRunProfileKind.Debug,
411411
this.pythonExecFactory,
412-
this.debugLauncher,
413412
);
414413
}
415414
return this.pytest.runTests(
@@ -439,7 +438,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
439438
testItems,
440439
token,
441440
request.profile?.kind === TestRunProfileKind.Debug,
442-
this.pythonExecFactory,
443441
);
444442
}
445443
// below is old way of running unittest execution

src/client/testing/testController/pytest/pytestExecutionAdapter.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import {
1212
IPythonExecutionFactory,
1313
SpawnOptions,
1414
} from '../../../common/process/types';
15+
import { EXTENSION_ROOT_DIR } from '../../../constants';
1516
import { removePositionalFoldersAndFiles } from './arguments';
16-
import { ITestDebugLauncher, LaunchOptions } from '../../common/types';
17-
import { PYTEST_PROVIDER } from '../../common/constants';
18-
import { EXTENSION_ROOT_DIR } from '../../../common/constants';
1917

2018
// eslint-disable-next-line @typescript-eslint/no-explicit-any
21-
// (global as any).EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR;
19+
(global as any).EXTENSION_ROOT_DIR = EXTENSION_ROOT_DIR;
2220
/**
2321
* Wrapper Class for pytest test execution. This is where we call `runTestCommand`?
2422
*/
@@ -49,12 +47,11 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
4947
testIds: string[],
5048
debugBool?: boolean,
5149
executionFactory?: IPythonExecutionFactory,
52-
debugLauncher?: ITestDebugLauncher,
5350
): Promise<ExecutionTestPayload> {
5451
traceVerbose(uri, testIds, debugBool);
5552
if (executionFactory !== undefined) {
5653
// ** new version of run tests.
57-
return this.runTestsNew(uri, testIds, debugBool, executionFactory, debugLauncher);
54+
return this.runTestsNew(uri, testIds, debugBool, executionFactory);
5855
}
5956
// if executionFactory is undefined, we are using the old method signature of run tests.
6057
this.outputChannel.appendLine('Running tests.');
@@ -67,7 +64,6 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
6764
testIds: string[],
6865
debugBool?: boolean,
6966
executionFactory?: IPythonExecutionFactory,
70-
debugLauncher?: ITestDebugLauncher,
7167
): Promise<ExecutionTestPayload> {
7268
const deferred = createDeferred<ExecutionTestPayload>();
7369
const relativePathToPytest = 'pythonFiles';
@@ -110,29 +106,16 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
110106
testArgs.splice(0, 0, '--rootdir', uri.fsPath);
111107
}
112108

113-
// why is this needed?
114109
if (debugBool && !testArgs.some((a) => a.startsWith('--capture') || a === '-s')) {
115110
testArgs.push('--capture', 'no');
116111
}
117-
const pluginArgs = ['-p', 'vscode_pytest', '-v'].concat(testArgs).concat(testIds);
118-
if (debugBool) {
119-
const pytestPort = this.testServer.getPort().toString();
120-
const pytestUUID = uuid.toString();
121-
const launchOptions: LaunchOptions = {
122-
cwd: uri.fsPath,
123-
args: pluginArgs,
124-
token: spawnOptions.token,
125-
testProvider: PYTEST_PROVIDER,
126-
pytestPort,
127-
pytestUUID,
128-
};
129-
console.debug(`Running debug test with arguments: ${pluginArgs.join(' ')}\r\n`);
130-
await debugLauncher!.launchDebugger(launchOptions);
131-
} else {
132-
const runArgs = ['-m', 'pytest'].concat(pluginArgs);
133-
console.debug(`Running test with arguments: ${runArgs.join(' ')}\r\n`);
134-
execService?.exec(runArgs, spawnOptions);
135-
}
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);
136119
} catch (ex) {
137120
console.debug(`Error while running tests: ${testIds}\r\n${ex}\r\n\r\n`);
138121
return Promise.reject(ex);

src/client/testing/testController/workspaceTestAdapter.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
} from './common/types';
3939
import { fixLogLines } from './common/utils';
4040
import { IPythonExecutionFactory } from '../../common/process/types';
41-
import { ITestDebugLauncher } from '../common/types';
4241

4342
/**
4443
* This class exposes a test-provider-agnostic way of discovering tests.
@@ -78,7 +77,6 @@ export class WorkspaceTestAdapter {
7877
token?: CancellationToken,
7978
debugBool?: boolean,
8079
executionFactory?: IPythonExecutionFactory,
81-
debugLauncher?: ITestDebugLauncher,
8280
): Promise<void> {
8381
if (this.executing) {
8482
return this.executing.promise;
@@ -112,7 +110,6 @@ export class WorkspaceTestAdapter {
112110
testCaseIds,
113111
debugBool,
114112
executionFactory,
115-
debugLauncher,
116113
);
117114
traceVerbose('executionFactory defined');
118115
} else {

0 commit comments

Comments
 (0)