DiamondLightSource / mx-bluesky

Bluesky plans, plan stubs, and utilities for MX beamlines
https://diamondlightsource.github.io/mx-bluesky/
Apache License 2.0
0 stars 2 forks source link

Fix unstable test in test_utils.py #654

Open olliesilvester opened 1 week ago

olliesilvester commented 1 week ago

Sometimes test_given_detector_move_fails_then_eiger_disarmed_and_correct_exception_returned fails, probably due to something in pytest not being cleaned up properly.

Here's the (not massively helpful) traceback for when it fails

__________ test_given_detector_move_fails_then_eiger_disarmed_and_correct_exception_returned __________
Traceback (most recent call last):
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/runner.py", line 341, in from_call
    result: TResult | None = func()
                             ^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/runner.py", line 242, in <lambda>
    lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/threadexception.py", line 92, in pytest_runtest_call
    yield from thread_exception_runtest_hook()
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/threadexception.py", line 68, in thread_exception_runtest_hook
    yield
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/unraisableexception.py", line 95, in pytest_runtest_call
    yield from unraisable_exception_runtest_hook()
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/unraisableexception.py", line 70, in unraisable_exception_runtest_hook
    yield
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/logging.py", line 846, in pytest_runtest_call
    yield from self._runtest_for(item, "call")
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/logging.py", line 829, in _runtest_for
    yield
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/capture.py", line 880, in pytest_runtest_call
    return (yield)
            ^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/skipping.py", line 257, in pytest_runtest_call
    return (yield)
            ^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/runner.py", line 174, in pytest_runtest_call
    item.runtest()
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/python.py", line 1627, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 182, in _multicall
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_result.py", line 100, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/_pytest/python.py", line 159, in pytest_pyfunc_call
    result = testfunction(**testargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/tests/unit_tests/hyperion/device_setup_plans/test_utils.py", line 84, in test_given_detector_move_fails_then_eiger_disarmed_and_correct_exception_returned
    RE(
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 973, in __call__
    plan_return = self._resume_task(init_func=_build_task)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1109, in _resume_task
    raise exc
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1751, in _run
    raise err
  File "/scratch/qqh35939/mx-bluesky/.venv/lib/python3.11/site-packages/bluesky/run_engine.py", line 1638, in _run
    msg.command,
    ^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'command'

Acceptance Criteria

malikrohail commented 1 week ago

can i fix this

olliesilvester commented 1 week ago

Yes please!