Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to run test in Pytest. #7844

Closed
ttSpace opened this issue Mar 4, 2024 · 5 comments
Closed

Fail to run test in Pytest. #7844

ttSpace opened this issue Mar 4, 2024 · 5 comments
Assignees

Comments

@ttSpace
Copy link

ttSpace commented Mar 4, 2024

Describe the bug

image

Python from Microsoft Store.

Steps to Reproduce

  1. Create Python Application Project.
  2. Add test_1.py file with code
def test_passing():
    assert 42 == 42
def test_failure():
    assert 42 == -13
  1. Set Test framework as "pytest" in python project properties page.
  2. Open TE with the Test > Windows > Test Explorer menu command
  3. Run Tests.

Expected behavior

Tests can be run successfully.

Additional context and screenshots

The test was skipped.

image

Logs

Output for General in the Output panel

========== Starting test run ==========
cd C:\Users\vting\source\repos\PythonApplication6\PythonApplication6\
set PYTHONPATH=C:\Users\vting\source\repos\PythonApplication6\PythonApplication6\
"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\python3.9.exe" "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py" C:\Users\vting\source\repos\PythonApplication6\PythonApplication6\ pytest "" 0 "" "" dummyfilename .\test_1.py::test_failure .\test_1.py::test_passing --junitxml=C:\Users\vting\source\repos\PythonApplication6\TestResults\junitresults_c9d7473e-b54e-4c9e-b97a-aff866df4e4a.xml --rootdir=C:\Users\vting\source\repos\PythonApplication6\PythonApplication6 -o junit_logging=all -o junit_family=xunit1
Traceback (most recent call last):
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 189, in <module>
    main()
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 30, in main
    run(testRunner, coverage_file, test_file, args)
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 119, in run
    patch_translate_non_printable()
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 136, in patch_translate_non_printable
    translate_non_printable =  getattr(_pytest.compat, "_translate_non_printable")
AttributeError: module '_pytest.compat' has no attribute '_translate_non_printable'
Results for pytest not found C:\Users\vting\source\repos\PythonApplication6\TestResults\junitresults_c9d7473e-b54e-4c9e-b97a-aff866df4e4a.xml
========== Test run finished: 2 Tests (0 Passed, 0 Failed, 2 Skipped) run in 395 ms ==========

@StellaHuang95
Copy link
Contributor

Seems like the version of pytest you installed is missing pytest.compat._translate_non_printable. What version of pytest do you have? Can you try updating the version and see if it repros?
image

@ttSpace
Copy link
Author

ttSpace commented Mar 5, 2024

@StellaHuang95 The Python installed from Microsoft Store.

image

@StellaHuang95
Copy link
Contributor

I am now able to repro it. It's an issue within the pytest 8.1.0. This version has been yanked, see https://doc.pytest.org/en/latest/changelog.html#pytest-8-1-0-yanked.

Once I revert back to 8.0.2, I was able to run tests without any issues.
image

@EJelmer
Copy link

EJelmer commented Apr 16, 2024

This is still broken in pytest v8.1.1.

@Jeroen6
Copy link

Jeroen6 commented Aug 22, 2024

This appears to be back with pytest 8.3.2 (python 3.11) in visual studio 17.11.1.

Did anyone have a permanent fix for this?

Traceback (most recent call last):
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 189, in <module>
    main()
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 30, in main
    run(testRunner, coverage_file, test_file, args)
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 119, in run
    patch_translate_non_printable()
  File "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\EXTENSIONS\MICROSOFT\PYTHON\CORE\testlauncher.py", line 136, in patch_translate_non_printable
    translate_non_printable =  getattr(_pytest.compat, "_translate_non_printable")
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module '_pytest.compat' has no attribute '_translate_non_printable'
Microsoft Visual Studio Community 2022
Version 17.11.1
VisualStudio.17.Release/17.11.1+35219.272
Microsoft .NET Framework
Version 4.8.09032
Python - Profiling support   17.0.24138.2
Python with Pylance   17.0.24138.2

workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants