-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Environment data
VS Code version: 1.20.1
Python Extension version: Latest (can't even find the version number from git hub or within vscode)
Python Version: Python 3.6.4 :: Anaconda, Inc.
OS and version: Windows 7
Actual behavior
Cannot configure debugging for pytest. Tried different launch configuration but no success.
- I tried with the default launch configuration:
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},
A. Pressing the "Debug test" on top of test case:
"Debug adapter process has terminated unexpectedly"
Then I will end up in a lingering debug mode that if I press the following I get the listed results
pause:
no effect
restart:
There was an error in starting the debug server. Error = {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":3000}
disconnect:
No effect
selecting and starting debug configuration from the status bar (at the bottom):
Traceback (most recent call last):
File "c:\workspace\ver-virtual-vehicle\test\test_fdx_decoder.py", line 7, in
from vv.fdx import decoder
ModuleNotFoundError: No module named 'vv'
Module import errors all of a sudden!!!
my directory structure is:
(workspace repo)/
src/
test/
B. Pressing F5
Traceback (most recent call last):
File "c:\workspace\ver-virtual-vehicle\test\test_fdx_decoder.py", line 7, in
from vv.fdx import decoder
ModuleNotFoundError: No module named 'vv'
And no lingering debugger!
- Using integrated terminal:
same as above!
{
"name": "Python: Terminal (integrated)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": []
},
First it fails:
"Debug adapter process has terminated unexpectedly"
Second time when I press in the bar and select the launcher again it outputs the following in the terminal:
$ cd "C:\workspace\ver-virtual-vehicle" ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" python "C:\Users\A281180.vscode\extensions\ms-python.python-2018.1.0\pythonFiles\PythonTools\visualstudio_
py_launcher.py" "C:\workspace\ver-virtual-vehicle" 50990 34806ad9-833a-4524-8cd6-18ca4aa74f14 DUMMYVALUE "c:\workspace\ver-virtual-vehicle\test\test_fdx_decoder.py"
Traceback (most recent call last):
File "c:\workspace\ver-virtual-vehicle\test\test_fdx_decoder.py", line 7, in
from vv.fdx import decoder
ModuleNotFoundError: No module named 'vv'
Can't import modules properly.
- Using a custom launcher:
{
"name": "PyTest",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"module": "pytest",
"args": [
"-sv"
],
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},
A. Pressing the "Debug test" on top of test case:
Lingering issue for days but after selecting the debugger again it eventually run all the test cases (more explanation below)!
B. Pressing F5
This works but it will run all the tests until it reaches the test case that I have a breakpoint on!
And of course it will continue running the rest of test cases after I am finished debugging my selected test case!
- Inconsistencies
I am pretty sure I tried one combination with the same launch config, that I managed to get what I want (just debug one test case!). After all, I tried so many things that I can't reproduce that behavior again.
It could be that the first time I select any launcher it works and stop of working after that!
P.s. The lack of proper documentation for debugging pytest is just wasting hours of developer times
Would you please write a step by step guide once and for all that will not lead to all these questions and github issues, this will save time for everyone (users and you guys)?
Expected behavior
I just want to add a break point on the first entry line of one of the my test cases and just press F5 and it should automatically stop on my breakpoint without running other test cases!
I do not want to add any files to my project just to satisfy my IDE needs! This means that the following solution is not ok IMHO:
https://donjayamanne.github.io/pythonVSCodeDocs/docs/debugging_debugging-pytest/
Steps to reproduce:
Described above!
Logs
Output from Python output panel
Output from Console window (Help->Developer Tools menu)