问题
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'
回答1:
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?
来源:https://stackoverflow.com/questions/58993126/no-test-under-python-unittest-in-visual-studio-2019