mantidproject / mantidimaging

Graphical toolkit for neutron imaging.
https://mantidproject.github.io/mantidimaging
GNU General Public License v3.0
13 stars 6 forks source link

Flaky SpectrumWidgetTest Warning #2309

Open MikeSullivan7 opened 1 month ago

MikeSullivan7 commented 1 month ago

Summary

When running pytest for the SpectrumWidgetTest, we sometimes get an AttributeError warning which come from different tests when re-run.

Steps To Reproduce

run make test or pytest mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py -W error::UserWarning to convert the warnings to errors to get more information.

Expected Behaviour

All test should pass with no warnings

Current Behaviour

AttributeErrors show as pytest warnings

Context

main branch

Failure Logs

With make test:

mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py::SpectrumWidgetTest::test_WHEN_add_range_called_THEN_region_and_label_set_correctly_2_range_300
  C:\Users\ddb29996\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\_pytest\unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored in garbage collection: None

  Traceback (most recent call last):
    File "C:\Users\ddb29996\mantidimaging\mantidimaging\gui\windows\main\view.py", line 493, in stack_names
      @property

  AttributeError: 'MainWindowView' object has no attribute 'stack_list'

    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

With pytest mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py -W error::UserWarning

(mantidimaging-dev) C:\Users\ddb29996\mantidimaging>pytest mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py -W error::UserWarning
======================================================= test session starts =======================================================
platform win32 -- Python 3.12.4, pytest-7.4.4, pluggy-1.5.0
Using --randomly-seed=1740163220
rootdir: C:\Users\ddb29996\mantidimaging
plugins: pyfakefs-5.3.5, cov-4.1.0, randomly-3.15.0, xdist-3.3.1
collected 23 items

mantidimaging\gui\windows\spectrum_viewer\test\spectrum_test.py .........F.............                                      [100%]

============================================================ FAILURES =============================================================
_______________ SpectrumWidgetTest.test_WHEN_set_roi_alpha_called_THEN_set_roi_visibility_flags_called_1_Invisible ________________

    @pytest.hookimpl(hookwrapper=True, tryfirst=True)
    def pytest_runtest_call() -> Generator[None, None, None]:
>       yield from unraisable_exception_runtest_hook()

..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\_pytest\unraisableexception.py:88:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def unraisable_exception_runtest_hook() -> Generator[None, None, None]:
        with catch_unraisable_exception() as cm:
            yield
            if cm.unraisable:
                if cm.unraisable.err_msg is not None:
                    err_msg = cm.unraisable.err_msg
                else:
                    err_msg = "Exception ignored in"
                msg = f"{err_msg}: {cm.unraisable.object!r}\n\n"
                msg += "".join(
                    traceback.format_exception(
                        cm.unraisable.exc_type,
                        cm.unraisable.exc_value,
                        cm.unraisable.exc_traceback,
                    )
                )
>               warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
E               pytest.PytestUnraisableExceptionWarning: Exception ignored in garbage collection: None
E
E               Traceback (most recent call last):
E                 File "C:\Users\ddb29996\mantidimaging\mantidimaging\gui\windows\main\view.py", line 493, in stack_names
E                   @property
E
E               AttributeError: 'MainWindowView' object has no attribute 'stack_list'

..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\_pytest\unraisableexception.py:78: PytestUnraisableExceptionWarning

During handling of the above exception, another exception occurred:

cls = <class '_pytest.runner.CallInfo'>, func = <function call_runtest_hook.<locals>.<lambda> at 0x000002314533C360>, when = 'call'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)

    @classmethod
    def from_call(
        cls,
        func: "Callable[[], TResult]",
        when: "Literal['collect', 'setup', 'call', 'teardown']",
        reraise: Optional[
            Union[Type[BaseException], Tuple[Type[BaseException], ...]]
        ] = None,
    ) -> "CallInfo[TResult]":
        """Call func, wrapping the result in a CallInfo.

        :param func:
            The function to call. Called without arguments.
        :param when:
            The phase in which the function is called.
        :param reraise:
            Exception or exceptions that shall propagate if raised by the
            function, instead of being wrapped in the CallInfo.
        """
        excinfo = None
        start = timing.time()
        precise_start = timing.perf_counter()
        try:
>           result: Optional[TResult] = func()

..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\_pytest\runner.py:341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\_pytest\runner.py:262: in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\pluggy\_hooks.py:513: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\pluggy\_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

hook_name = 'pytest_runtest_call'
hook_impl = <HookImpl plugin_name='unraisableexception', plugin=<module '_pytest.unraisableexception' from 'C:\\Users\\ddb29996\\AppData\\Local\\miniforge3\\envs\\mantidimaging-dev\\Lib\\site-packages\\_pytest\\unraisableexception.py'>>
e = PytestUnraisableExceptionWarning('Exception ignored in garbage collection: None\n\nTraceback (most recent call last):\...493, in stack_names\n    @property\n    \nAttributeError: \'MainWindowView\' object has no attribute \'stack_list\'\n')

    def _warn_teardown_exception(
        hook_name: str, hook_impl: HookImpl, e: BaseException
    ) -> None:
        msg = "A plugin raised an exception during an old-style hookwrapper teardown.\n"
        msg += f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
        msg += f"{type(e).__name__}: {e}\n"
        msg += "For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning"  # noqa: E501
>       warnings.warn(PluggyTeardownRaisedWarning(msg), stacklevel=5)
E       pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.
E       Plugin: unraisableexception, Hook: pytest_runtest_call
E       PytestUnraisableExceptionWarning: Exception ignored in garbage collection: None
E
E       Traceback (most recent call last):
E         File "C:\Users\ddb29996\mantidimaging\mantidimaging\gui\windows\main\view.py", line 493, in stack_names
E           @property
E
E       AttributeError: 'MainWindowView' object has no attribute 'stack_list'
E
E       For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning

..\AppData\Local\miniforge3\envs\mantidimaging-dev\Lib\site-packages\pluggy\_callers.py:50: PluggyTeardownRaisedWarning
===================================================== short test summary info =====================================================
FAILED mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py::SpectrumWidgetTest::test_WHEN_set_roi_alpha_called_THEN_set_roi_visibility_flags_called_1_Invisible - pluggy.PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.

Screenshot(s)