小编mgf*_*mgf的帖子

VS Code / Python / 使用调试器调试 pytest 测试

使用 pytest 运行测试时,如何让 VS Code 在出现故障时将我放入调试器?

Pytest 捕获所有错误并断言,并且 VS 代码仅在未捕获的错误上调用调试器(我可以将其更改为引发的异常,但它会在尝试下引发的所有错误时停止)。

我试图设置--pdb为 pytest 参数,但这会导致错误:

============================= test session starts =============================
platform win32 -- Python 3.8.1, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: c:\Projects\debugtest, inifile: pytest.ini
collected 1 item

test.py F
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Traceback (most recent call last):
  File "C:\Projects\debugtest\test.py", line 4, in test_with_assert
    assert 42==2.71828
AssertionError: assert 42 == 2.71828
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>
> c:\projects\debugtest\test.py(4)test_with_assert()
-> assert 42==2.71828
(Pdb)

PYDEV DEBUGGER WARNING:
sys.settrace() should …
Run Code Online (Sandbox Code Playgroud)

python pytest visual-studio-code

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

pytest ×1

python ×1

visual-studio-code ×1