Skip to content
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

Debug Test in vscode fails inside container #1415

Closed
GrosLalo opened this issue Jun 28, 2020 · 5 comments
Closed

Debug Test in vscode fails inside container #1415

GrosLalo opened this issue Jun 28, 2020 · 5 comments
Assignees

Comments

@GrosLalo
Copy link

GrosLalo commented Jun 28, 2020

Configuration:

I am using the following version of VSCode:

Version: 1.46.1
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:13:08.304Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.3.0-59-generic snap

With the Python Extension ms-python.python version v2020.6.8. The only PIPs installed are:

Package           Version
----------------- -------
astroid           2.4.2
attrs             19.3.0
autopep8          1.5.3
isort             4.3.21
lazy-object-proxy 1.4.3
mccabe            0.6.1
more-itertools    8.4.0
packaging         20.4
pip               20.1.1
pluggy            0.13.1
py                1.8.2
pycodestyle       2.6.0
pylint            2.5.3
pyparsing         2.4.7
pytest            5.4.3
setuptools        47.1.1
six               1.15.0
toml              0.10.1
wcwidth           0.2.4
wheel             0.34.2
wrapt             1.12.1

Problem

I am trying to debug my python tests in vscode and i get the following error in the debug console:

============================= test session starts ==============================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /workspaces/test_python_debugging
collected 0 items / 1 error

==================================== ERRORS ====================================
_________________ ERROR collecting tst/dummy/test_unit_math.py _________________
ImportError while importing test module '/workspaces/test_python_debugging/tst/dummy/test_unit_math.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tst/dummy/test_unit_math.py:5: in <module>
    from dummy.math import add
E   ModuleNotFoundError: No module named 'dummy'
--------------- generated xml file: /tmp/tmp-188wLObs4r6II9x.xml ---------------
=========================== short test summary info ============================
ERROR tst/dummy/test_unit_math.py
=============================== 1 error in 0.19s ===============================
ERROR: not found: /workspaces/test_python_debugging/tst/dummy/test_unit_math.py::test_addition
(no name '/workspaces/test_python_debugging/tst/dummy/test_unit_math.py::test_addition' in any of [<Module tst/dummy/test_unit_math.py>])

The tests themselves run fine in the terminal. In other terms there is no issue with not being able to find the "missing" module. Example:

0f617e2a72ee [/workspaces/test_python_debugging]$ python -m pytest tst/**/te
st*.py -k test_addition
=========================== test session starts ============================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /workspaces/test_python_debugging
collected 1 item                                                           

tst/dummy/test_unit_math.py .                                        [100%]

============================ 1 passed in 0.01s =============================
0f617e2a72ee [/workspaces/test_python_debugging]$ 

The way I am launching the debugger is by clicking on the Debug Test link of the given test. Below is the .devcontainer.json configuration being used:

{
  "image": "test_python_debugging",
  "extensions": [
    "ms-python.python"
  ],
  "mounts": [
    "source=${localWorkspaceFolder},target=/app,type=bind,consistency=cached"
  ],
  "settings": {
    "terminal.integrated.shell.linux": "/bin/ash",
    "terminal.integrated.shellArgs.linux": [
      "-l"
    ],
    "python.testing.pytestArgs": [
      "tst",
      "-k test_unit"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.pythonPath": "/usr/local/bin/python"
  },
  "containerUser": "app",
  "containerEnv": {
    "PYTHONPATH": "/app/src"
  }
}

I think that this is most likely a bug and would like to report it. Otherwise, can someone tell what I am missing in my .devcontainer.json?

@karthiknadig karthiknadig added the bug Something isn't working label Jun 30, 2020
@int19h
Copy link
Contributor

int19h commented Jun 30, 2020

If you open the Output pane, and select Python Test Log, you should see the exact command line it's running pytest with - this might help identify any missing options.

If there's nothing there that sticks out, can you share that log?

@GrosLalo
Copy link
Author

GrosLalo commented Jul 2, 2020

Hi @int19h,

Please find below the output of running pytest from the output tab ("Python Test Log"):

Error: Error: cannot open vscode-remote://dev-container%2B2f686f6d652f76696b2f50726f6a656374732f776f726b2f61646170746976652d6f616d2d6c696e6b2d73796e63/app/tst/dummy/test_unit_math.py. Detail: Unable to read file 'vscode-remote://dev-container+2f686f6d652f76696b2f50726f6a656374732f776f726b2f61646170746976652d6f616d2d6c696e6b2d73796e63/app/tst/dummy/test_unit_math.py' (Error: Unable to resolve non-existing file 'vscode-remote://dev-container+2f686f6d652f76696b2f50726f6a656374732f776f726b2f61646170746976652d6f616d2d6c696e6b2d73796e63/app/tst/dummy/test_unit_math.py')

After i remove all docker images and recreate everything and repeat the experiment, the problem persists but now the output pane for "Python Test Log" is:

============================= test session starts ==============================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /workspaces/code/test_python_debugging
collected 1 item

tst/dummy/test_unit_math.py .                                            [100%]

--------------- generated xml file: /tmp/tmp-182VgM5tpzq4F3x.xml ---------------
============================== 1 passed in 0.01s ===============================

I have added the project to this comment. Thanks for looking into this.

test_python_debugging.zip

@int19h
Copy link
Contributor

int19h commented Jul 2, 2020

Hm, so with your new repro (with the fresh container), it looks like it's working? Or are you still seeing the error in the other pane?

@GrosLalo
Copy link
Author

GrosLalo commented Jul 3, 2020

Yes the problem persists. I get the same error as in the description when i debug. (But, as you asked me to run pytest which i understood to be without debug so, just run debug, i get the output i mention in the previous comment). In short my problem is still here <- I cannot break and debug code.

@karthiknadig karthiknadig removed the bug Something isn't working label Nov 2, 2023
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Nov 2, 2023
@judej
Copy link

judej commented Jan 3, 2024

Closing old issue. If this is still a problem, please reopen with the information requested. thanks

@judej judej closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants