Python 在vscode中调试pytest unitest会导致AttributeError sys在退出时没有属性

Python 在vscode中调试pytest unitest会导致AttributeError sys在退出时没有属性,python,visual-studio-code,pytest,visual-studio-debugging,Python,Visual Studio Code,Pytest,Visual Studio Debugging,我使用Ubuntu 18.04上的visual studio代码1.27.2和Anaconda版本4.5.10来管理我的虚拟环境 我在vscode中安装了Anaconda和python扩展 我使用一个虚拟环境进行了一个简单的测试,在这个虚拟环境中,我只安装了Pythest和pylint for python 3.6 如果我运行此简单脚本: import pytest def test_test(): assert True == True VisualStudio代码可以完美地运行测

我使用Ubuntu 18.04上的visual studio代码1.27.2和Anaconda版本4.5.10来管理我的虚拟环境

我在vscode中安装了Anaconda和python扩展

我使用一个虚拟环境进行了一个简单的测试,在这个虚拟环境中,我只安装了Pythest和pylint for python 3.6

如果我运行此简单脚本:

import pytest

def test_test():
    assert True == True
VisualStudio代码可以完美地运行测试,并在输出控制台中显示结果

但是,如果我尝试调试这个脚本,测试运行并在退出时得到一个AttributeError sys没有属性,我不明白为什么?我做错什么了吗?这是VisualStudio代码调试器或pytest集成的错误吗

堆栈跟踪:

File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/__main__.py", line 211, in <module> singlesession=args.single_session)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/__main__.py", line 205, in main debug_main(addr, name, kind, *extra, **kwargs)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/_local.py", line 28, in debug_main run_module(address, name, *extra, **kwargs)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/_local.py", line 53, in run_module run(argv, addr, **kwargs)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/_local.py", line 125, in _run _pydevd.main()
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 1743, in main debugger.connect(host, port)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 1099, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "/home/leerro/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 1123, in _exec runpy._run_module_as_main(module_name, alter_argv=False)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pytest.py", line 77, in <module> raise SystemExit(pytest.main())
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/_pytest/config/__init__.py", line 67, in main return config.hook.pytest_cmdline_main(config=config)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec return self._inner_hookexec(hook, methods, kwargs)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda> firstresult=hook.spec_opts.get('firstresult'),
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall return outcome.get_result()
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result raise ex[1].with_traceback(ex[2])
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall res = hook_impl.function(*args)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/_pytest/main.py", line 208, in pytest_cmdline_main return wrap_session(config, _main)
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/_pytest/main.py", line 203, in wrap_session config._ensure_unconfigure()
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/_pytest/config/__init__.py", line 611, in _ensure_unconfigure fin()
File "/home/leerro/anaconda3/envs/py36TF/lib/python3.6/site-packages/_pytest/debugging.py", line 67, in fin sys.breakpointhook = sys.__breakpointhook__
AttributeError: module 'sys' has no attribute '__breakpointhook__'
我尝试在launch.json中使用此配置从调试会话运行它,但它给出了相同的堆栈跟踪和错误

{
     "name": "Debug Pytest",
     "type": "python",
     "request": "launch",
     "stopOnEntry": false,
     "pythonPath": "${config:python.pythonPath}",
     "module": "pytest",
     "envFile": "${workspaceFolder}/.env",
     "console": "integratedTerminal",
}
我有点迷路了,不知道下一步该去哪里找。当然,我仍然可以调试代码,因为只有在退出时才会发生异常,但我发现这很麻烦,我不知道这是Visual Studio代码还是配置的问题

任何帮助都将不胜感激

这是一个将在下一版本中修复的问题,该问题将包含在下一版本的Python VS代码扩展中

{
     "name": "Debug Pytest",
     "type": "python",
     "request": "launch",
     "stopOnEntry": false,
     "pythonPath": "${config:python.pythonPath}",
     "module": "pytest",
     "envFile": "${workspaceFolder}/.env",
     "console": "integratedTerminal",
}