microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.52k stars 673 forks source link

Fail to run test in Pytest. #7844

Closed ttSpace closed 4 months ago

ttSpace commented 4 months ago

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
  3. Set Test framework as "pytest" in python project properties page.
  4. Open TE with the Test > Windows > Test Explorer menu command
  5. 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 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 commented 4 months ago

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 commented 4 months ago

@StellaHuang95 The Python installed from Microsoft Store.

image

StellaHuang95 commented 4 months ago

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 commented 2 months ago

This is still broken in pytest v8.1.1.