No test under python unittest in visual studio 2019

余生长醉 提交于 2021-01-28 18:40:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!