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

test_handle_exception sometimes fails #17090

Closed
5 of 10 tasks
juliangilbey opened this issue Dec 24, 2021 · 2 comments
Closed
5 of 10 tasks

test_handle_exception sometimes fails #17090

juliangilbey opened this issue Dec 24, 2021 · 2 comments
Assignees
Milestone

Comments

@juliangilbey
Copy link
Contributor

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

This test seemingly randomly fails, but apparently only when run within a larger testsuite. It's part of my attempt to identify the source of a randomly appearing segfault.

What steps reproduce the problem?

(sid-minimal)jdg@euler:/build/spyder-jdg/build-area/spyder-5.2.1+dfsg1$ CI=true HOME=/tmp/tmp.6vHkjBKUv7 xvfb-run -a -s "-screen 0 1024x768x24 +extension GLX" python3.10 -m pytest -vv -rw --durations=10 -W ignore::UserWarning -x -k 'not test_get_pydoc and not test_qtbug35861 and not test_run_python_script_in_terminal and not test_run_python_script_in_terminal_blank_wdir and not test_run_python_script_in_terminal_with_wdir_empty and not test_find_external_plugins and not test_load_time and not test_status_bar_conda_interpreter_status and not test_conda.py and not test_objectexplorer_collection_types and not test_pyenv.py and not test_object_arrays_display and not test_profiler_config_dialog.py' spyder
============================= test session starts ==============================
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.10.0, pluggy-0.13.0 -- /usr/bin/python3.10
cachedir: .pytest_cache
PyQt5 5.15.6 -- Qt runtime 5.15.2 -- Qt compiled 5.15.2
rootdir: /build/spyder-jdg/build-area/spyder-5.2.1+dfsg1, configfile: pytest.ini
plugins: flaky-3.7.0, xvfb-2.0.0, mock-3.6.1, cov-3.0.0, order-1.0.0, qt-4.0.2, lazy-fixture-0.6.3
collecting ... QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-jdg'
collected 1202 items / 26 deselected / 1176 selected                           

spyder/app/tests/test_cli_options.py::test_get_options PASSED            [  0%]
spyder/app/tests/test_mainwindow.py::test_single_instance_and_edit_magic SKIPPED [  0%]
spyder/app/tests/test_mainwindow.py::test_default_plugin_actions SKIPPED [  0%]
spyder/app/tests/test_mainwindow.py::test_change_types_in_varexp SKIPPED [  0%]
spyder/app/tests/test_mainwindow.py::test_preferences_change_interpreter SKIPPED [  0%]
spyder/plugins/completion/providers/kite/utils/tests/test_install.py::test_kite_install SKIPPED [  0%]
spyder/plugins/completion/tests/test_plugin.py::test_plugin_completion_gather PASSED [  0%]
spyder/plugins/completion/tests/test_plugin.py::test_plugin_first_response_request PASSED [  0%]
[... lots of successful tests snipped ...]
spyder/plugins/completion/tests/test_configdialog.py::test_config_dialog[config_dialog0] PASSED [ 24%]
spyder/plugins/completion/tests/test_plugin.py::test_configuration_merge PASSED [ 24%]
spyder/plugins/completion/tests/test_plugin.py::test_provider_detection PASSED [ 24%]
spyder/plugins/console/tests/test_plugin.py::test_run_code PASSED        [ 24%]
spyder/plugins/console/tests/test_plugin.py::test_completions PASSED     [ 24%]
spyder/plugins/console/tests/test_plugin.py::test_handle_exception FAILED [ 24%]

=================================== FAILURES ===================================
____________________________ test_handle_exception _____________________________

console_plugin = <spyder.plugins.console.plugin.Console object at 0x7ff7043051b0>
mocker = <pytest_mock.plugin.MockerFixture object at 0x7ff7043fa7d0>

    def test_handle_exception(console_plugin, mocker):
        """Test that error dialog is called."""
        widget = console_plugin.get_widget()
        shell = widget.shell
    
        # Avoid showing the error dialog.
        mocker.patch('spyder.widgets.reporterror.SpyderErrorDialog.show',
                     return_value=None)
    
        # --- Test internal errors in Spyder
        # Write error in the console
        error = """Traceback (most recent call last):
      File "/home/foo/miniconda3/envs/py37/lib/python3.7/code.py", line 90, in runcode
        exec(code, self.locals)
      File "<console>", line 2, in <module>
    ZeroDivisionError: division by zero
    """
        shell.append_text_to_shell(error, error=True, prompt=False)
    
        # Make sure the error dialog was generated.
        assert widget.error_dlg is not None
    
        # Check that the traceback was shown in the error dialog.
        widget.error_dlg.details_btn.clicked.emit()
        assert 'foo' in widget.error_dlg.details.toPlainText()
        assert 'code.py' in widget.error_dlg.details.toPlainText()
    
        # Remove error dialog
        widget.error_dlg = None
    
        # --- Test PyLS errors
>       console_plugin.handle_exception(
            dict(
                text=error,
                is_traceback=True,
                title='Internal Python Language Server error',
            )
        )

/build/spyder-jdg/build-area/spyder-5.2.1+dfsg1/spyder/plugins/console/tests/test_plugin.py:124: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/build/spyder-jdg/build-area/spyder-5.2.1+dfsg1/spyder/plugins/console/plugin.py:217: in handle_exception
    self.get_widget().handle_exception(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <spyder.plugins.console.widgets.main_widget.ConsoleWidget object at 0x7ff704305120>
error_data = {'is_traceback': True, 'text': 'Traceback (most recent call last):\n  File "/home/foo/miniconda3/envs/py37/lib/python3...nsole>", line 2, in <module>\nZeroDivisionError: division by zero\n', 'title': 'Internal Python Language Server error'}
sender = <PyQt5.QtCore.QThread object at 0x7ff76e197490>

    @Slot(dict)
    def handle_exception(self, error_data, sender=None):
        """
        Exception ocurred in the internal console.
    
        Show a QDialog or the internal console to warn the user.
    
        Handle any exception that occurs during Spyder usage.
    
        Parameters
        ----------
        error_data: dict
            The dictionary containing error data. The expected keys are:
            >>> error_data= {
                "text": str,
                "is_traceback": bool,
                "repo": str,
                "title": str,
                "label": str,
                "steps": str,
            }
        sender: spyder.api.plugins.SpyderPluginV2, optional
            The sender plugin. Default is None.
    
        Notes
        -----
        The `is_traceback` key indicates if `text` contains plain text or a
        Python error traceback.
    
        The `title` and `repo` keys indicate how the error data should
        customize the report dialog and Github error submission.
    
        The `label` and `steps` keys allow customizing the content of the
        error dialog.
        """
        text = error_data.get("text", None)
        is_traceback = error_data.get("is_traceback", False)
        title = error_data.get("title", "")
        label = error_data.get("label", "")
        steps = error_data.get("steps", "")
    
        # Skip errors without traceback (and no text) or dismiss
        if ((not text and not is_traceback and self.error_dlg is None)
                or self.dismiss_error):
            return
    
        InstallerInternalError(title + text)
    
        # Retrieve internal plugins
        internal_plugins = PLUGIN_REGISTRY.internal_plugins
    
        # Get if sender is internal or not
        is_internal_plugin = True
        if sender is not None:
            sender_name = getattr(
>               sender, 'NAME', getattr(sender, 'CONF_SECTION'))
E           AttributeError: 'QThread' object has no attribute 'CONF_SECTION'

/build/spyder-jdg/build-area/spyder-5.2.1+dfsg1/spyder/plugins/console/widgets/main_widget.py:393: AttributeError
=============================== warnings summary ===============================
../../../../usr/lib/python3/dist-packages/qtpy/__init__.py:65
  /usr/lib/python3/dist-packages/qtpy/__init__.py:65: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    from distutils.version import LooseVersion

../../../../usr/lib/python3/dist-packages/astroid/modutils.py:51
  /usr/lib/python3/dist-packages/astroid/modutils.py:51: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
    from distutils.sysconfig import get_python_lib  # pylint: disable=import-error

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /build/spyder-jdg/build-area/spyder-5.2.1+dfsg1/spyder/plugins/ipythonconsole/widgets/shell.py:937: DeprecationWarning: ShellWidget._syntax_style_changed is deprecated in traitlets 4.1: use @observe and @unobserve instead.
    def _syntax_style_changed(self):

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /usr/lib/python3/dist-packages/jupyter_client/manager.py:64: DeprecationWarning: There is no current event loop
    self._ready = Future()

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /usr/lib/python3/dist-packages/jupyter_client/utils.py:14: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /usr/lib/python3/dist-packages/jupyter_client/utils.py:21: DeprecationWarning: There is no current event loop
    future = asyncio.ensure_future(coro(*args, **kwargs))

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /usr/lib/python3/dist-packages/tornado/ioloop.py:263: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /usr/lib/python3/dist-packages/tornado/platform/asyncio.py:326: DeprecationWarning: There is no current event loop
    self.old_asyncio = asyncio.get_event_loop()

spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /usr/lib/python3/dist-packages/tornado/platform/asyncio.py:193: DeprecationWarning: There is no current event loop
    old_loop = asyncio.get_event_loop()

-- Docs: https://docs.pytest.org/en/stable/warnings.html
===Flaky Test Report===

test_conda_env_activation passed 1 out of the required 1 times. Success!
test_run_code passed 1 out of the required 1 times. Success!
test_completions passed 1 out of the required 1 times. Success!

===End Flaky Test Report===
============================= slowest 10 durations =============================
2.10s call     spyder/plugins/completion/providers/fallback/tests/test_fallback.py::test_file_open_close
1.93s call     spyder/plugins/completion/providers/fallback/tests/test_fallback.py::test_token_update
1.93s call     spyder/plugins/explorer/widgets/tests/test_fileassociations.py::test_file_assoc_widget
1.44s setup    spyder/plugins/completion/tests/test_plugin.py::test_plugin_completion_gather
1.41s call     spyder/plugins/completion/tests/test_plugin.py::test_plugin_completion_gather
1.10s call     spyder/plugins/completion/providers/fallback/tests/test_fallback.py::test_tokenize[jl]
1.07s call     spyder/plugins/completion/providers/fallback/tests/test_fallback.py::test_tokenize[c]
1.05s call     spyder/plugins/explorer/widgets/tests/test_explorer.py::test_clicked
1.04s call     spyder/plugins/completion/providers/fallback/tests/test_fallback.py::test_tokenize[css]
1.03s call     spyder/plugins/completion/providers/fallback/tests/test_fallback.py::test_tokenize[cpp]
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
=== 1 failed, 137 passed, 154 skipped, 26 deselected, 16 warnings in 41.58s ====

From the traceback, it would seem as though something (the QThread object?) has not been correctly initialised. But I don't know why that should be different if the test is run in isolation and if it's run as part of a larger group of tests, and also why it is

Versions

  • Spyder version: 5.2.1
  • Python version: 3.9 and 3.10
  • Qt version: 5.15.2
  • PyQt version: 5.15.6+dfsg-1+b1
  • Operating System name/version: Debian testing and unstable

Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.6.0               :  7.27.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.0 (OK)
jellyfish >=0.7               :  0.8.9 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.3.0 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.1 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.7.1 (OK)
pylint >=2.5.0                :  2.12.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.3.2;<1.4.0          :  1.3.3 (OK)
pylsp_black >=1.0.0           :  1.0.1 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.2.1;<5.3.0      :  5.2.1 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  58.2.0 (OK)
sphinx >=0.6.6                :  4.3.2 (OK)
spyder_kernels >=2.2.0;<2.3.0 :  2.2.0 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  0.29.24 (OK)
matplotlib >=2.0.0            :  3.3.4 (OK)
numpy >=1.7                   :  1.21.5 (OK)
pandas >=1.1.1                :  1.3.4 (OK)
scipy >=0.17.0                :  1.7.1 (OK)
sympy >=0.7.3                 :  1.7.1 (OK)
@ccordoba12 ccordoba12 changed the title spyder/plugins/console/tests/test_plugin.py::test_handle_exception sometimes fails test_handle_exception sometimes fails Dec 24, 2021
@ccordoba12 ccordoba12 added this to the v5.2.2 milestone Dec 24, 2021
@ccordoba12 ccordoba12 self-assigned this Dec 24, 2021
@ccordoba12
Copy link
Member

It's part of my attempt to identify the source of a randomly appearing segfault.

This is related to PyQt 5.15 and it'll be fixed fixed in our 5.3.0 version, to be released in a couple of months, so don't hold your breath about it (I haven't had time to leave a comment about that in the other issues you opened before).

Please don't package Spyder before that version (as Fedora and Arch) because it crashes with a segfault at close (and it's not our fault because things are working fine with PyQt 5.12).

@juliangilbey
Copy link
Contributor Author

OK, @ccordoba12, I will wait until 5.3.0, and thanks for all your work on this! The current version in Debian (stable, testing and unstable) is 4.2.1, but it will disappear from testing fairly soon, as the old python-language-server no longer builds. There's no particular rush from our side: the next Debian stable release won't be for quite some time yet (it's still a bit over a year before the pre-release freeze), and we've also got to wait for the nbconvert package to be sorted out, which may also take a while. In the meantime, I'm happy to test patches and so on; I can try snapshot 5.x versions if that is helpful to you.

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

No branches or pull requests

2 participants