在 Visual Studio 2019 中没有在 python unittest 下进行测试 [英] No test under python unittest in visual studio 2019
问题描述
我在 Visual Studio 2019(版本 16.3.9)中有一个现有的 python 项目,其中包含在 Visual Studio 2017 下为 unittest.py 创建的单元测试.我已经为 unittest 配置了该项目,因为这是在 Visual Studio 2019 中需要的:>
但是没有显示单元测试.
但我收到以下错误:
文件C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\run_adapter.py",第 17 行,在<模块>工具, cmd, subargs, toolargs = parse_args()文件C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\__main__.py",第 81 行,在 parse_argssubsub = add_subparser(cmdname, toolname, subsubs)文件C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\__main__.py",第 26 行,在 pytest_add_cli_subparser从 .导入pytest文件C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\pytest\__init__.py",第 7 行,在 <模块>从 ._discovery 导入发现文件C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\pytest\_discovery.py",第 31 行,<模块>patch_translate_non_printable()文件C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\pytest\_discovery.py",第15行,在patch_printable_non中translate_non_printable = getattr(_pytest.compat, "_translate_non_printable")AttributeError: 模块_pytest.compat"没有属性_translate_non_printable"
您能否检查测试"下的输出窗口以获取传递给 run_adapter.py 的参数,并确保在那里发现 unittest?
示例
xxx\EXTENSIONS\MICROSOFT CORPORATION\PYTHON\16.0.0\PythonFiles\testing_tools\run_adapter.py 发现 unittest --output-file xx\Local\Temp\tmpF743.tmp -- .测试*.py
你的环境中也安装了pytest吗?如果是,是哪个版本?
I have an existing python project in visual studio 2019 (Version16.3.9) containing unit test created for unittest.py under visual studio 2017. I already configered the project for unittest, because this is needed in visual studio 2019:
But there are no unit tests shown.
But I got the following error:
File "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\run_adapter.py", line 17, in <module>
tool, cmd, subargs, toolargs = parse_args()
File "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\__main__.py", line 81, in parse_args
subsub = add_subparser(cmdname, toolname, subsubs)
File "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\__main__.py", line 26, in pytest_add_cli_subparser
from . import pytest
File "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\pytest\__init__.py", line 7, in <module>
from ._discovery import discover
File "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\pytest\_discovery.py", line 31, in <module>
patch_translate_non_printable()
File "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\PythonFiles\testing_tools\adapter\pytest\_discovery.py", line 15, in patch_translate_non_printable
translate_non_printable = getattr(_pytest.compat, "_translate_non_printable")
AttributeError: module '_pytest.compat' has no attribute '_translate_non_printable'
Can you check your output windows under "Tests" for the arguments passed to run_adapter.py, and make sure discover unittest there?
example
xxx\EXTENSIONS\MICROSOFT CORPORATION\PYTHON\16.0.0\PythonFiles\testing_tools\run_adapter.py discover unittest --output-file xx\Local\Temp\tmpF743.tmp -- . test*.py
Also is pytest installed in your environment? If so which version?
这篇关于在 Visual Studio 2019 中没有在 python unittest 下进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!