Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter {
});

const result = execService?.execObservable(runArgs, spawnOptions);
resultProc = result?.proc;

// Take all output from the subprocess and add it to the test output channel. This will be the pytest output.
// Displays output to user and ensure the subprocess doesn't run into buffer overflow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as assert from 'assert';
import { TestRun, Uri, TestRunProfileKind, DebugSessionOptions } from 'vscode';
import { CancellationTokenSource, TestRun, Uri, TestRunProfileKind, DebugSessionOptions } from 'vscode';
import * as typeMoq from 'typemoq';
import * as sinon from 'sinon';
import * as path from 'path';
Expand Down Expand Up @@ -182,6 +182,28 @@ suite('pytest test execution adapter', () => {
typeMoq.Times.once(),
);
});
test('cancelling pytest execution kills the subprocess', async () => {
utilsWriteTestIdsFileStub.resolves('testIdPipe-mockName');
utilsStartRunResultNamedPipeStub.callsFake((_callback, deferredTillServerClose, token) => {
token?.onCancellationRequested(() => deferredTillServerClose.resolve());
return Promise.resolve('runResultPipe-mockName');
});
const cancellationToken = new CancellationTokenSource();
const testRun = typeMoq.Mock.ofType<TestRun>();
testRun.setup((t) => t.token).returns(() => cancellationToken.token);
const killStub = sinon.stub(mockProc, 'kill');
const uri = Uri.file(myTestPath);
adapter = new PytestTestExecutionAdapter(configService);

const execution = adapter.runTests(uri, [], TestRunProfileKind.Run, testRun.object, execFactory.object);
await deferred4.promise;
cancellationToken.cancel();

sinon.assert.calledOnce(killStub);
mockProc.emit('close', 0, null);
await execution;
cancellationToken.dispose();
});
test('pytest execution respects settings.testing.cwd when present', async () => {
const deferred2 = createDeferred();
const deferred3 = createDeferred();
Expand Down
Loading