当前位置: 首页 > 知识库问答 >
问题:

vscode中的调试测试在容器内失败

仉刚洁
2023-03-14

我正在使用以下版本的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

使用Python扩展ms-python.pythonversionv2020.6.8。唯一安装的PIP是:

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

我试图在vscode中调试python测试,在调试控制台中出现以下错误:

============================= 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>])

测试本身在终端上运行良好。换句话说,找不到“缺失”模块没有问题。例子:

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]$ 

我启动调试器的方式是单击给定测试的Debug Test链接。例子:

下面是。开发者。正在使用的json配置:

{
  "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"
  }
}

有人知道我在配置方面缺少什么吗?

共有1个答案

党宇定
2023-03-14

您需要适当地指定您的PYTHONPATH,以便使用src/。您的。devcontainer.json将目录设为/app,但是您在测试中的回溯显示代码位于/workspace/test_python_debugging中。

 类似资料:
  • 我正在使用Angular 9、Node v14和e2e测试,使用Cucumber、量角器和量角器Cucumber框架。 量角器。conf.js tsconfig。e2e。json 发射json package.json 我可以在VSCode中启动调试器,但问题是每个断点都是未绑定的断点。 我还尝试在tsconfig中添加。e2e。json和我也尝试加入launch。json 问题似乎是ts节点在内

  • 我需要在VsCode上调试我的反应原生应用程序,我是新的反应原生开发...:)我搜索并遵循不同的方法,但没有运气...:(首先,我遵循此方法https://medium.com/@Tunvirrahmantushs/react-nate-debug-with-vscode-in-imple-steps-bf39b6331e67并遵循此方法https://www.youtube.com/watch?

  • 按 ctrl + shift + d , 然后点击左上角的小齿轮配置,把下面代码复制进去。 在你的ts代码里面打上断点,点击绿色的小箭头开始调试即可。 这个非常有用,比你使用 console.log 调试快很多。 { // Use IntelliSense to learn about possible Node.js debug attributes. // Hover to v

  • 我在vscode中创建了两个简单的Spring Boot Web服务,其中一个Web服务调用另一个,所以我需要同时运行它们,同时调试其中至少一个。如果我独立调试它们,它们都可以工作,例如,如果我右键单击主类并从菜单中选择调试命令。例如,我执行以下顺序: 在调试中启动Service1 通过从浏览器调用URL来测试Service1,并验证它是否有效(确实有效) 在调试中启动Service2 检查Ser

  • 我试图找出如何在Visual Studio2015中调试在Docker容器中执行的单元测试和集成测试。 null

  • 问题内容: 有没有办法在单元测试失败时自动启动调试器? 现在,我只是手动使用pdb.set_trace(),但这非常繁琐,因为我需要每次都添加它并在最后将其取出。 例如: 问题答案: 我更正了在异常而不是set_trace上调用post_mortem的代码。