From dd5ae6b1f54c7d2e75786498e083df24105c3c19 Mon Sep 17 00:00:00 2001 From: Nikolay Kondratyev Date: Tue, 5 Feb 2019 09:47:58 +0300 Subject: [PATCH 1/2] Pass pytest arguments for debug --- src/pytest/pytestTestRunner.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pytest/pytestTestRunner.ts b/src/pytest/pytestTestRunner.ts index 1970c39..5476b3c 100644 --- a/src/pytest/pytestTestRunner.ts +++ b/src/pytest/pytestTestRunner.ts @@ -72,7 +72,7 @@ pytest.main(sys.argv[1:], plugins=[PythonTestExplorerDiscoveryOutputPlugin()])`; return { module: 'pytest', cwd: config.getCwd(), - args: test !== this.adapterId ? [test] : [], + args: this.getRunArguments(test, config.getPytestConfiguration().pytestArguments), envFile: config.envFile(), }; } @@ -112,11 +112,13 @@ pytest.main(sys.argv[1:], plugins=[PythonTestExplorerDiscoveryOutputPlugin()])`; const additionalEnvironment = await EnvironmentVariablesLoader.load(config.envFile(), this.logger); const { file, cleanupCallback } = await this.createTemporaryFile(); + const runArguments = [`--junitxml=${file}`].concat( + this.getRunArguments(test, config.getPytestConfiguration().pytestArguments)); const testExecution = runScript({ pythonPath: config.pythonPath(), script: PytestTestRunner.PYTEST_WRAPPER_SCRIPT, cwd: config.getCwd(), - args: this.getRunArguments(test, file, config.getPytestConfiguration().pytestArguments), + args: runArguments, environment: additionalEnvironment, }); this.testExecutions.set(test, testExecution); @@ -134,7 +136,7 @@ pytest.main(sys.argv[1:], plugins=[PythonTestExplorerDiscoveryOutputPlugin()])`; return ['--collect-only'].concat(argumentsToPass); } - private getRunArguments(test: string, outFile: string, rawPytestArguments: string[]): string[] { + private getRunArguments(test: string, rawPytestArguments: string[]): string[] { const argumentParser = this.configureCommonArgumentParser(); argumentParser.addArgument( ['--setuponly', '--setup-only'], @@ -152,7 +154,7 @@ pytest.main(sys.argv[1:], plugins=[PythonTestExplorerDiscoveryOutputPlugin()])`; ['--trace'], { dest: 'trace', action: 'storeTrue' }); const [, argumentsToPass] = argumentParser.parseKnownArgs(rawPytestArguments); - return [`--junitxml=${outFile}`].concat(argumentsToPass).concat(test !== this.adapterId ? [test] : []); + return argumentsToPass.concat(test !== this.adapterId ? [test] : []); } private configureCommonArgumentParser() { From 80cfaec8eafe8d0bddec2c0a239e23a988e95736 Mon Sep 17 00:00:00 2001 From: Nikolay Kondratyev Date: Wed, 6 Feb 2019 09:31:33 +0300 Subject: [PATCH 2/2] Import error fix --- src/pytest/pytestTestRunner.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pytest/pytestTestRunner.ts b/src/pytest/pytestTestRunner.ts index 5476b3c..483c550 100644 --- a/src/pytest/pytestTestRunner.ts +++ b/src/pytest/pytestTestRunner.ts @@ -24,16 +24,17 @@ import sys import json import py -from _pytest.compat import getfslineno - - def get_line_number(item): location = getattr(item, 'location', None) if location is not None: return location[1] obj = getattr(item, 'obj', None) if obj is not None: - return getfslineno(obj)[1] + try: + from _pytest.compat import getfslineno + return getfslineno(obj)[1] + except: + pass return None