简体   繁体   中英

No test under python unittest in visual studio 2019

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM