Skip to content

Commit 28b6054

Browse files
authored
Revert discovery of pytest by scraping the output (#5517)
* Revert * Fix paths * Update change log * Fixes
1 parent d505aac commit 28b6054

24 files changed

+1251
-3150
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# Changelog
22

3-
## 2019.4.1 (24 April 2019)
3+
## 2019.4.2 (29 April 2019)
4+
5+
### Fixes
6+
7+
1. Revert discovery of `pytest` tests to use the approach of scraping the output.
8+
([#5458](https://github.com/Microsoft/vscode-python/issues/5458))
9+
10+
## 2019.4.11987 (24 April 2019)
411

512
### Fixes
613

714
1. Remove trailing commas in JSON files.
815
(thanks [Romain](https://github.com/quarthex))
916
([#5437](https://github.com/Microsoft/vscode-python/issues/5437))
1017

11-
## 2019.4.0 (23 April 2019)
18+
## 2019.4.11881 (23 April 2019)
1219

1320
### Enhancements
1421

src/client/telemetry/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export enum EventName {
4343
UNITTEST_DISABLE = 'UNITTEST.DISABLE',
4444
UNITTEST_RUN = 'UNITTEST.RUN',
4545
UNITTEST_DISCOVER = 'UNITTEST.DISCOVER',
46-
UNITTEST_DISCOVER_WITH_PYCODE = 'UNITTEST.DISCOVER.WITH.PYTHONCODE',
4746
UNITTEST_CONFIGURE = 'UNITTEST.CONFIGURE',
4847
UNITTEST_CONFIGURING = 'UNITTEST.CONFIGURING',
4948
UNITTEST_VIEW_OUTPUT = 'UNITTEST.VIEW_OUTPUT',

src/client/telemetry/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ export interface IEventNamePropertyMapping {
312312
[EventName.UNITTEST_CONFIGURING]: TestConfiguringTelemetry;
313313
[EventName.TERMINAL_CREATE]: TerminalTelemetry;
314314
[EventName.UNITTEST_DISCOVER]: TestDiscoverytTelemetry;
315-
[EventName.UNITTEST_DISCOVER_WITH_PYCODE]: never | undefined;
316315
[EventName.UNITTEST_RUN]: TestRunTelemetry;
317316
[EventName.UNITTEST_STOP]: never | undefined;
318317
[EventName.UNITTEST_DISABLE]: never | undefined;

src/client/testing/common/services/discovery.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/client/testing/common/testUtils.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,31 @@ function getParentTestFolder(tests: Tests, item: TestFolder | TestFile): TestFol
360360
return getParentTestFolderForFile(tests, item as TestFile);
361361
}
362362

363+
/**
364+
* Returns the parent test folder give a given test file.
365+
*
366+
* @param {Tests} tests
367+
* @param {TestFile} file
368+
* @returns {(TestFolder | undefined)}
369+
*/
370+
function getParentTestFolderForFile(tests: Tests, file: TestFile): TestFolder | undefined {
371+
return tests.testFolders.find(folder => folder.testFiles.some(item => item === file));
372+
}
373+
374+
/**
375+
* Returns the parent test folder for a given test folder.
376+
*
377+
* @param {Tests} tests
378+
* @param {TestFolder} folder
379+
* @returns {(TestFolder | undefined)}
380+
*/
381+
function getParentTestFolderForFolder(tests: Tests, folder: TestFolder): TestFolder | undefined {
382+
if (tests.rootTestFolders.indexOf(folder) >= 0) {
383+
return;
384+
}
385+
return tests.testFolders.find(item => item.folders.some(child => child === folder));
386+
}
387+
363388
/**
364389
* Gets the parent test file for a test item.
365390
*
@@ -395,31 +420,6 @@ export function getParentSuite(tests: Tests, suite: TestSuite | TestFunction): T
395420
return;
396421
}
397422

398-
/**
399-
* Returns the parent test folder give a given test file.
400-
*
401-
* @param {Tests} tests
402-
* @param {TestFile} file
403-
* @returns {(TestFolder | undefined)}
404-
*/
405-
function getParentTestFolderForFile(tests: Tests, file: TestFile): TestFolder | undefined {
406-
return tests.testFolders.find(folder => folder.testFiles.some(item => item === file));
407-
}
408-
409-
/**
410-
* Returns the parent test folder for a given test folder.
411-
*
412-
* @param {Tests} tests
413-
* @param {TestFolder} folder
414-
* @returns {(TestFolder | undefined)}
415-
*/
416-
function getParentTestFolderForFolder(tests: Tests, folder: TestFolder): TestFolder | undefined {
417-
if (tests.rootTestFolders.indexOf(folder) >= 0) {
418-
return;
419-
}
420-
return tests.testFolders.find(item => item.folders.some(child => child === folder));
421-
}
422-
423423
/**
424424
* Given a test function will return the corresponding flattened test function.
425425
*

src/client/testing/pytest/services/discoveryService.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { inject, injectable } from 'inversify';
4+
import { inject, injectable, named } from 'inversify';
55
import { CancellationTokenSource } from 'vscode';
66
import { IServiceContainer } from '../../../ioc/types';
77
import { PYTEST_PROVIDER } from '../../common/constants';
8-
import { ITestDiscoveryService, ITestsHelper, TestDiscoveryOptions, Tests } from '../../common/types';
8+
import { ITestDiscoveryService, ITestRunner, ITestsHelper, ITestsParser, Options, TestDiscoveryOptions, Tests } from '../../common/types';
99
import { IArgumentsService, TestFilter } from '../../types';
1010

1111
@injectable()
1212
export class TestDiscoveryService implements ITestDiscoveryService {
1313
private argsService: IArgumentsService;
1414
private helper: ITestsHelper;
15-
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {
15+
private runner: ITestRunner;
16+
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer,
17+
@inject(ITestsParser) @named(PYTEST_PROVIDER) private testParser: ITestsParser) {
1618
this.argsService = this.serviceContainer.get<IArgumentsService>(IArgumentsService, PYTEST_PROVIDER);
1719
this.helper = this.serviceContainer.get<ITestsHelper>(ITestsHelper);
20+
this.runner = this.serviceContainer.get<ITestRunner>(ITestRunner);
1821
}
1922
public async discoverTests(options: TestDiscoveryOptions): Promise<Tests> {
2023
const args = this.buildTestCollectionArgs(options);
@@ -39,7 +42,7 @@ export class TestDiscoveryService implements ITestDiscoveryService {
3942

4043
return this.helper.mergeTests(results);
4144
}
42-
protected buildTestCollectionArgs(options: TestDiscoveryOptions) {
45+
private buildTestCollectionArgs(options: TestDiscoveryOptions) {
4346
// Remove unwnted arguments (which happen to be test directories & test specific args).
4447
const args = this.argsService.filterArguments(options.args, TestFilter.discovery);
4548
if (options.ignoreCache && args.indexOf('--cache-clear') === -1) {
@@ -48,19 +51,24 @@ export class TestDiscoveryService implements ITestDiscoveryService {
4851
if (args.indexOf('-s') === -1) {
4952
args.splice(0, 0, '-s');
5053
}
54+
args.splice(0, 0, '--collect-only');
5155
return args;
5256
}
53-
protected async discoverTestsInTestDirectory(options: TestDiscoveryOptions): Promise<Tests> {
57+
private async discoverTestsInTestDirectory(options: TestDiscoveryOptions): Promise<Tests> {
5458
const token = options.token ? options.token : new CancellationTokenSource().token;
55-
const discoveryOptions = { ...options };
56-
discoveryOptions.args = ['discover', 'pytest', '--', ...options.args];
57-
discoveryOptions.token = token;
59+
const runOptions: Options = {
60+
args: options.args,
61+
cwd: options.cwd,
62+
workspaceFolder: options.workspaceFolder,
63+
token,
64+
outChannel: options.outChannel
65+
};
5866

59-
const discoveryService = this.serviceContainer.get<ITestDiscoveryService>(ITestDiscoveryService, 'common');
60-
if (discoveryOptions.token && discoveryOptions.token.isCancellationRequested) {
67+
const data = await this.runner.run(PYTEST_PROVIDER, runOptions);
68+
if (options.token && options.token.isCancellationRequested) {
6169
return Promise.reject<Tests>('cancelled');
6270
}
6371

64-
return discoveryService.discoverTests(discoveryOptions);
72+
return this.testParser.parse(data, options);
6573
}
6674
}

0 commit comments

Comments
 (0)