Skip to content

Update to ophyd-async v0.20.1 - #2122

Open
oliwenmandiamond wants to merge 16 commits into
mainfrom
update_to_ophyd_async_0_20
Open

Update to ophyd-async v0.20.1#2122
oliwenmandiamond wants to merge 16 commits into
mainfrom
update_to_ophyd_async_0_20

Conversation

@oliwenmandiamond

@oliwenmandiamond oliwenmandiamond commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Update to latest ophyd-async version v0.20.1

Instructions to reviewer on how to test:

1.Check tests pass
2. Check AI conversions of setting mock bluesky verbs done correctly

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

oliwenmandiamond and others added 5 commits July 22, 2026 13:24
ophyd-async 0.20.1 adds set_mock_attr (in ophyd_async.core) and enforces
that test code can no longer assign directly to attribute names that
collide with bluesky protocol verbs (set, read, trigger, kickoff,
complete, prepare, describe, check_value). Replace direct assignments
like `signal.set = AsyncMock(...)` with `set_mock_attr(signal, "set",
AsyncMock(...))` across the affected test files and fixtures.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQPRwf3pUved4ihrBLPi1g
The set_mock_attr fixes in the previous commit cover every reserved-attr
NameError that this autouse fixture was blanket-suppressing, so the
mask is no longer needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQPRwf3pUved4ihrBLPi1g

coretl commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

ophyd-async 0.20.1 set_mock_attr fixes

Bumped the ophyd-async[ca,pva] pin to >=0.20.1 (now resolved in uv.lock) and fixed the remaining reserved-attr test failures using the new set_mock_attr helper (imported from ophyd_async.core — it isn't re-exported from ophyd_async.testing in this release).

Tests fixed with set_mock_attr (direct signal.set = mock/.read =/.trigger =/etc. assignments replaced with set_mock_attr(signal, "attr", mock)):

  • tests/devices/beamlines/i03/test_beamsize.py, i03/test_undulator_dcm.py, i04/test_beamsize.py
  • tests/devices/beamlines/i06_shared/test_i06_apple2controller.py, i09_2/test_i09_2_motors.py, i10/test_i10_apple2.py, i15_1/test_hexapod.py, i17/test_i17_apple2.py, i21/test_toolpoint_motion.py
  • tests/devices/electron_analyser/base/test_detector_logic.py
  • tests/devices/insertion_device/test_apple2_controller.py, test_apple2_undulator.py, test_energy.py, test_polarisation.py
  • tests/devices/oav/conftest.py, tests/devices/oav/test_oav.py
  • tests/devices/test_attenuator.py, test_bart_robot.py, test_common_mirrors.py, test_focusing_mirror.py, test_gridscan.py, test_smargon.py, test_zebra.py, test_zocalo_results.py

Also removed the temporary OPHYD_ASYNC_ALLOW_RESERVED_ATTRS=YES autouse fixture from tests/conftest.py added in a previous commit — the set_mock_attr fixes above cover every case it was masking, confirmed by re-running the full suite with the mask removed (identical failure set before/after).

Remaining failures left for a human (all pre-existing, none addressable by set_mock_attr):

  • 56 tests/devices/beamlines/{i09_2_shared,i10}/test_i09_apple2.py / test_i10_apple2.py cases — TypeError: mock_config_client.<locals>.my_side_effect() missing 1 required positional argument: 'desired_return_type'. This is a second, still-broken duplicate mock_config_client fixture in src/dodal/testing/fixtures/devices/hard_undulator.py (positional-only my_side_effect(file_path, desired_return_type, reset_cached_result)) — the "Fix ConfigClient issue" commit only fixed the copy in src/dodal/testing/fixtures/devices/apple2.py. Likely just needs the same default-args treatment applied there.
  • 1 tests/devices/beamlines/i15_1/test_robot.py::test_puck_program_loaded_before_position_selected — EPICS/IOC timeout, infra-related.

Full suite: 3268 passed, 58 failed (all the mock_config_client cases above), 1 skipped.


Generated by Claude Code

set_mock_attr(device, "attr", mock) doesn't let pyright narrow
device.attr to the mock's type, so later device.attr.assert_*() calls
failed with reportAttributeAccessIssue. Capture set_mock_attr's return
value (it returns the mock unchanged, per its own docstring) and assert
on that instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EQPRwf3pUved4ihrBLPi1g

coretl commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Fixed a pyright regression from the set_mock_attr change: set_mock_attr(device, "attr", mock) doesn't let pyright narrow device.attr to the mock's type, so later device.attr.assert_*(...) calls were failing type-checking with reportAttributeAccessIssue. Fixed by capturing set_mock_attr's return value (it returns the mock unchanged, per its own docstring) and asserting on that instead, across the 14 affected test files. pyright and the full test suite are clean again (same 58 pre-existing mock_config_client failures as before, nothing new).


Generated by Claude Code

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.16%. Comparing base (3b77d81) to head (6b424b6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2122      +/-   ##
==========================================
- Coverage   99.16%   99.16%   -0.01%     
==========================================
  Files         354      354              
  Lines       13842    13841       -1     
==========================================
- Hits        13726    13725       -1     
  Misses        116      116              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oliwenmandiamond
oliwenmandiamond marked this pull request as ready for review July 29, 2026 09:30
@oliwenmandiamond
oliwenmandiamond requested a review from a team as a code owner July 29, 2026 09:30
@oliwenmandiamond oliwenmandiamond changed the title Update to ophyd-async v0.20 Update to ophyd-async v0.20.1 Jul 29, 2026

coretl commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

CI is fully green now — the "Standardise config client" merge (#2099) replaced the duplicate mock_config_client fixture mechanism and fixed the remaining 56/58 failures I'd flagged as out-of-scope. Confirmed locally on 6b424b6: 3375 passed, 1 skipped, 0 failed; pre-commit, ruff, and pyright all clean. All GitHub Actions checks (lint, tests × 4 Python versions, docs, dist, codecov) are passing.


Generated by Claude Code

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

Successfully merging this pull request may close these issues.

3 participants