-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Debugging pytest fails #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We do have docs on debugging tests, they are just not pytest-specific as there is nothing special from the perspective of the extension between e.g. pytest and unittest. (The docs you link to are from before Microsoft took over development of the extension.) As for the import error, that's because your code is in a
I have opened #924 to track the idea of making this more obvious. Otherwise I can't reproduce since I can run an individual test both from the code lens and command palette and have it stop on a breakpoint as expected. |
Hi Brett, I have followed the new issue that you opened and tried to clarify there, that this is not about finding the test case. But I've been asked to not post comments there. There is no problem with detection of the test! I can run the test by simply clicking on "Run Test" or typing "pytest" from shell and there is no need of adding any .env file. The problem arises when you want to debug your test:
If you try it several times you will end up in a dangling debugger that you cannot even proceed with debugging! I have attached my simple try out structure along with my lanuch.json so you can reproduce this: |
What do yo umean by
It is upto you to configure the debugger to run a specific test file/test case. You'll need to check the documentation of pytest on how you can run a specific test file/test case.
No inconsistency here. It works perfectly fine for me, without any
That's yet another issue, please do create a separate issue for this with instructions (along with the sample code and files such as |
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.
{
"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!
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.
{
"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!
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 panelOutput from
Console window
(Help->Developer Tools menu)The text was updated successfully, but these errors were encountered: