microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.12k stars 29.27k forks source link

`MatplotlibDeprecationWarning` running pytest with PythonDebugger #233413

Open StefanieSenger opened 1 hour ago

StefanieSenger commented 1 hour ago

Type: Bug

Does this issue occur when all extensions are disabled?: Yes

VS Code version: Code 1.94.2 (384ff7382de624fb94dbaf6da11977bba1ecd427, 2024-10-09T16:08:44.566Z) OS version: Linux x64 6.11.5-arch1-1

versions: pytest==8.3.1 matplotlib==3.9.2

I am getting MatplotlibDeprecationWarning that causes an error with test_warn failed when I run this with the PythonDebugger in the Testing extension:

import warnings
import pytest

def f():
    warnings.warn("Test", UserWarning)

def test_warn():
    with pytest.warns(UserWarning, match="Test"):
        f()

I set a breakpoint in the line of with pytest.warns(UserWarning, match="Test")::

Traceback:

/home/stefanie/code/scikit-learn_dev/scikit-learn/sklearn/test_warn.py::test_warn failed: def test_warn():
>       with pytest.warns(UserWarning, match="Test"):

sklearn/test_warn.py:8: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
<stringsource>:69: in cfunc.to_py.__Pyx_CFunc_b0409f__29_pydevd_sys_monitoring_cython_object__lParen__etc_to_py_4code_4line.wrap
    ???
_pydevd_sys_monitoring\\_pydevd_sys_monitoring_cython.pyx:1429: in _pydevd_sys_monitoring_cython._line_event
    ???
_pydevd_sys_monitoring\\_pydevd_sys_monitoring_cython.pyx:1471: in _pydevd_sys_monitoring_cython._internal_line_event
    ???
_pydevd_sys_monitoring\\_pydevd_sys_monitoring_cython.pyx:1278: in _pydevd_sys_monitoring_cython._stop_on_breakpoint
    ???
_pydevd_sys_monitoring\\_pydevd_sys_monitoring_cython.pyx:1906: in _pydevd_sys_monitoring_cython._do_wait_suspend
    ???
../../../.vscode/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py:2197: in do_wait_suspend
    keep_suspended = self._do_wait_suspend(thread, frame, event, arg, trace_suspend_type, from_this_thread, frames_tracker)
../../../.vscode/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py:2223: in _do_wait_suspend
    self._activate_gui_if_needed()
../../../.vscode/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py:1685: in _activate_gui_if_needed
    activate_function()
../../../.vscode/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydevd.py:1668: in <lambda>
    "matplotlib": lambda: activate_matplotlib(do_enable_gui),
../../../.vscode/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py:99: in activate_matplotlib
    is_interactive = is_interactive_backend(backend)
../../../.vscode/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py:59: in is_interactive_backend
    from matplotlib.rcsetup import interactive_bk, non_interactive_bk  # @UnresolvedImport
../../../.pyenv/versions/3.12.2/envs/scikit-learn_dev/lib/python3.12/site-packages/matplotlib/_api/__init__.py:216: in __getattr__
    return props[name].__get__(instance)
../../../.pyenv/versions/3.12.2/envs/scikit-learn_dev/lib/python3.12/site-packages/matplotlib/_api/deprecation.py:161: in __get__
    emit_warning()
../../../.pyenv/versions/3.12.2/envs/scikit-learn_dev/lib/python3.12/site-packages/matplotlib/_api/deprecation.py:196: in emit_warning
    warn_deprecated(
../../../.pyenv/versions/3.12.2/envs/scikit-learn_dev/lib/python3.12/site-packages/matplotlib/_api/deprecation.py:99: in warn_deprecated
    warn_external(warning, category=MatplotlibDeprecationWarning)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

message = MatplotlibDeprecationWarning('The interactive_bk attribute was deprecated in Matplotlib 3.9 and will be removed in 3.11. Use ``matplotlib.backends.backend_registry.list_builtin(matplotlib.backends.BackendFilter.INTERACTIVE)`` instead.')
category = <class 'matplotlib._api.deprecation.MatplotlibDeprecationWarning'>

    def warn_external(message, category=None):
        """
        `warnings.warn` wrapper that sets *stacklevel* to "outside Matplotlib".

        The original emitter of the warning can be obtained by patching this
        function back to `warnings.warn`, i.e. ``_api.warn_external =
        warnings.warn`` (or ``functools.partial(warnings.warn, stacklevel=2)``,
        etc.).
        """
        frame = sys._getframe()
        for stacklevel in itertools.count(1):
            if frame is None:
                # when called in embedded context may hit frame is None
                break
            if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.(?!tests\.))",
                            # Work around sphinx-gallery not setting __name__.
                            frame.f_globals.get("__name__", "")):
                break
            frame = frame.f_back
        # preemptively break reference cycle between locals and the frame
        del frame
>       warnings.warn(message, category, stacklevel)
E       matplotlib._api.deprecation.MatplotlibDeprecationWarning: The interactive_bk attribute was deprecated in Matplotlib 3.9 and will be removed in 3.11. Use ``matplotlib.backends.backend_registry.list_builtin(matplotlib.backends.BackendFilter.INTERACTIVE)`` instead.

../../../.pyenv/versions/3.12.2/envs/scikit-learn_dev/lib/python3.12/site-packages/matplotlib/_api/__init__.py:381: MatplotlibDeprecationWarning

I set a breakpoint in the line of f() and press continue:

Traceback:

/home/stefanie/code/scikit-learn_dev/scikit-learn/sklearn/test_warn.py::test_warn failed: def test_warn():
>       with pytest.warns(UserWarning, match="Test"):
E       matplotlib._api.deprecation.MatplotlibDeprecationWarning: The interactive_bk attribute was deprecated in Matplotlib 3.9 and will be removed in 3.11. Use ``matplotlib.backends.backend_registry.list_builtin(matplotlib.backends.BackendFilter.INTERACTIVE)`` instead.

sklearn/test_warn.py:8: MatplotlibDeprecationWarning

I would have expected not to see this warning and be able to continue with the debugging. Running the test with Testing without debug points or running the tests with pytest on the terminal works just fine.

vs-code-engineering[bot] commented 1 hour ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.95.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

StefanieSenger commented 1 hour ago

I have upgraded my VSCode version to 1.95.2. and the issue still persists.