Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/blueapi/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ def reload_environment(
raise BlueskyRemoteControlError(
"Failed to tear down the environment"
) from e
# Invalidate cached plans/devices so subsequent access reflects the
# newly reloaded environment rather than the previous one.
self.__dict__.pop("plans", None)
self.__dict__.pop("devices", None)
return self._wait_for_reload(
status,
timeout,
Expand Down
22 changes: 22 additions & 0 deletions tests/unit_tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,28 @@ def test_reload_environment_failure(
client.reload_environment()


def test_reload_environment_refreshes_cached_plans_and_devices(
client: BlueapiClient,
mock_rest: Mock,
):
# Prime caches with the original plans and devices.
initial_plans = list(client.plans)
initial_devices = list(client.devices)
assert {p.name for p in initial_plans} == {"foo", "bar"}
assert set(initial_devices) == {"foo", "bar"}

new_plans = PlanResponse(plans=[PlanModel(name="missing")])
new_devices = DeviceResponse(devices=[DeviceModel(name="baz", protocols=[])])
mock_rest.get_plans.return_value = new_plans
mock_rest.get_devices.return_value = new_devices
mock_rest.get_environment.return_value = NEW_ENV

client.reload_environment()

assert {p.name for p in client.plans} == {"missing"}
assert set(client.devices) == {"baz"}


def test_abort(
client: BlueapiClient,
mock_rest: Mock,
Expand Down