From @craigbrett17 on July 11, 2017 11:48
Environment data
VS Code version: 1.13.1
Python Extension version: 0.6.7
Python Version: 2.7.13
OS and version: Windows 10 (64 bit) Version 10.0.14393 Build 14393
Actual behavior
When you try and use the "Run current unit test file" command or similar on a file in a tests folder, it doesn't pick up on user code in an adjacent folder and you receive ImportErrors. There is no way to make the terminal aim at a different PYTHONPATH, like there is if you launch using a launch configuration (F5ing, basically). I believe PTVS had a way of adding folders and they'd be picked up that way, but I'm not sure what that's doing under the hood, so I'm not sure how I'd replicate that within VSCode and the Python extension.
Expected behavior
There should either be a setting to set env variables for terminal launching, or else some other way to effect this. Or else maybe some documentation on how to do this if this is already possible.
Steps to reproduce:
- Have a project structure with some code in one folder and some unit tests in an adjacent "tests" folder
- Attempt to run your unit tests using the python actions (I can't remember what the technical name for them is). You'll want the ones that run using the terminal.
You'll notice that you can run this code using the launch.json configs, because you can set the PYTHONPATH to the workspaceRoot. I've also done this using a task that uses our makefile to run the tests and can set the env in there to make it work. But this isn't possible in the terminal.
Settings
Your launch.json (if dealing with debugger issues):
{
"version": "0.2.0",
"configurations": [
{
"name": "Run service",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/mysource/__init__.py",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
Your settings.json:
// Place your settings in this file to overwrite default and user settings.
{
"python.unitTest.pyTestArgs": [],
"python.unitTest.pyTestEnabled": true
}
Logs
Output from Python output panel
============================= test session starts =============================
platform win32 -- Python 2.7.13, pytest-2.9.1, py-1.4.34, pluggy-0.3.1
rootdir: d:\development\myproj, inifile:
plugins: cov-2.2.1, html-1.8.0, twisted-1.5
collected 1 items / 17 errors
<DoctestTextfile 'test-requirements.txt'>
=================================== ERRORS ====================================
____________ ERROR collecting tests/grammar_tests/test_grammar.py _____________
tests\grammar_tests\test_grammar.py:1: in <module>
from mysource import Parser
E ImportError: No module named mysource
...
=========================== 1 error in 0.56 seconds ===========================
Copied from original issue: DonJayamanne/pythonVSCode#1077
From @craigbrett17 on July 11, 2017 11:48
Environment data
VS Code version: 1.13.1
Python Extension version: 0.6.7
Python Version: 2.7.13
OS and version: Windows 10 (64 bit) Version 10.0.14393 Build 14393
Actual behavior
When you try and use the "Run current unit test file" command or similar on a file in a tests folder, it doesn't pick up on user code in an adjacent folder and you receive ImportErrors. There is no way to make the terminal aim at a different PYTHONPATH, like there is if you launch using a launch configuration (F5ing, basically). I believe PTVS had a way of adding folders and they'd be picked up that way, but I'm not sure what that's doing under the hood, so I'm not sure how I'd replicate that within VSCode and the Python extension.
Expected behavior
There should either be a setting to set env variables for terminal launching, or else some other way to effect this. Or else maybe some documentation on how to do this if this is already possible.
Steps to reproduce:
You'll notice that you can run this code using the launch.json configs, because you can set the PYTHONPATH to the workspaceRoot. I've also done this using a task that uses our makefile to run the tests and can set the env in there to make it work. But this isn't possible in the terminal.
Settings
Your launch.json (if dealing with debugger issues):
{ "version": "0.2.0", "configurations": [ { "name": "Run service", "type": "python", "request": "launch", "stopOnEntry": false, "pythonPath": "${config:python.pythonPath}", "program": "${workspaceRoot}/mysource/__init__.py", "env": { "PYTHONPATH": "${workspaceRoot}" }, "envFile": "${workspaceRoot}/.env", "debugOptions": [ "WaitOnAbnormalExit", "WaitOnNormalExit", "RedirectOutput" ] } ] }Your settings.json:
Logs
Output from
Pythonoutput panelCopied from original issue: DonJayamanne/pythonVSCode#1077