Skip to content

Commit 381c18a

Browse files
authored
Merge pull request #118 from robberwick/better-no-backend-detection
fix: ensure backend check correctly raises exception when not set
2 parents fce5a6e + 8235b05 commit 381c18a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/blinkstick/clients/blinkstick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __getattribute__(self, name):
7171
if callable(attr) and not getattr(attr, "no_backend_required", False):
7272

7373
def wrapper(*args, **kwargs):
74-
if self.backend is None:
74+
if not getattr(self, "backend", None):
7575
raise NotConnected("No backend set")
7676
return attr(*args, **kwargs)
7777

tests/clients/test_blinkstick.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ def test_instantiate():
1717
assert bs is not None
1818

1919

20-
def test_all_methods_require_backend(make_blinkstick):
20+
def test_all_methods_require_backend():
2121
"""Test that all methods require a backend."""
22-
bs = make_blinkstick()
23-
bs.backend = None # noqa
22+
# Create an instance of BlinkStick. Note that we do not use the mock, or pass a device.
23+
# This is deliberate, as we want to test that all methods raise an exception when the backend is not set.
24+
bs = BlinkStick()
2425

2526
class_methods = (
2627
method

0 commit comments

Comments
 (0)