Python 来自Visual Studio的py.test-'_调试输出';对象没有属性';关闭';
我正在将Python工具用于Visual Studio和py.test。如果在不进行调试的情况下运行脚本,我可以很好地使用pytest,但是在进行调试的情况下运行脚本时,脚本会崩溃。下面是我的代码和在控制台窗口中得到的输出。我在谷歌上搜索过答案,但没有找到解决这个问题的方法;似乎以前没有人遇到过这样的问题。我运行的是Visual Studio 2013,PTVS为2.1 VS 2013Python 来自Visual Studio的py.test-'_调试输出';对象没有属性';关闭';,python,visual-studio,pytest,ptvs,Python,Visual Studio,Pytest,Ptvs,我正在将Python工具用于Visual Studio和py.test。如果在不进行调试的情况下运行脚本,我可以很好地使用pytest,但是在进行调试的情况下运行脚本时,脚本会崩溃。下面是我的代码和在控制台窗口中得到的输出。我在谷歌上搜索过答案,但没有找到解决这个问题的方法;似乎以前没有人遇到过这样的问题。我运行的是Visual Studio 2013,PTVS为2.1 VS 2013 #Code import pytest if __name__ == "__main__": pyte
#Code
import pytest
if __name__ == "__main__":
pytest.main("--resultlog=resultlog.txt")
#Output
! C:\Python34\lib\site-packages\colorama\ansitowin32.py
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\_pytest\main.py", line 80, in wrap_session
config.do_configure()
File "C:\Python34\lib\site-packages\_pytest\config.py", line 618, in do_configure
self.hook.pytest_configure(config=self)
File "C:\Python34\lib\site-packages\_pytest\core.py", line 521, in __call__
return self._docall(self.methods, kwargs)
File "C:\Python34\lib\site-packages\_pytest\core.py", line 528, in _docall
firstresult=self.firstresult).execute()
File "C:\Python34\lib\site-packages\_pytest\core.py", line 394, in execute
res = method(*args)
File "C:\Python34\lib\site-packages\_pytest\terminal.py", line 41, in pytest_configure
reporter = TerminalReporter(config, sys.stdout)
File "C:\Python34\lib\site-packages\_pytest\terminal.py", line 101, in __init__
self._tw = self.writer = py.io.TerminalWriter(file)
File "C:\Python34\lib\site-packages\py\_io\terminalwriter.py", line 130, in __init__
file = colorama.AnsiToWin32(file).stream
File "C:\Python34\lib\site-packages\colorama\ansitowin32.py", line 68, in __init__
convert = on_windows and not wrapped.closed and not on_emulated_windows and is_a_tty(wrapped)
AttributeError: '_DebuggerOutput' object has no attribute 'closed'
Q:如何解决此错误,以便我可以在Visual Studio内部进行调试?
这是PTV中的一个问题,已在即将发布的2.2版本中修复 目前还没有修复版本,但您可以自己应用,因为它位于.py文件中,不需要重新编译。您需要的文件是: C:\Users\…\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\Microsoft\Python Visual Studio工具\2.1\VisualStudio\u py\u debugger.py 在其中查找类
\u DebuggerOutput
,并在其末尾添加以下内容:
def __getattr__(self, name):
return getattr(self.old_out, name)
这是PTV中的一个问题,已在即将发布的2.2版本中修复
目前还没有修复版本,但您可以自己应用,因为它位于.py文件中,不需要重新编译。您需要的文件是:
C:\Users\…\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\Microsoft\Python Visual Studio工具\2.1\VisualStudio\u py\u debugger.py
在其中查找类\u DebuggerOutput
,并在其末尾添加以下内容:
def __getattr__(self, name):
return getattr(self.old_out, name)
可能是PTV中的错误。pytest假设标准输出是一个文件,而它是另一个文件(一个缺少
closed
属性的\u DebuggerOutput
对象)。这可能很容易修复,只需在PTV中找到\u DebuggerOutput
类定义,并将closed=False
添加到其定义中即可。PTV中可能存在Bug。pytest假设标准输出是一个文件,而它是另一个文件(一个缺少closed
属性的\u DebuggerOutput
对象)。这可能很容易解决,只需在PTVS中找到\u DebuggerOutput
类定义,并将closed=False
添加到其定义中即可。