diff --git a/src/blinkstick/clients/blinkstick.py b/src/blinkstick/clients/blinkstick.py index ca3d4e8..d03c9d8 100644 --- a/src/blinkstick/clients/blinkstick.py +++ b/src/blinkstick/clients/blinkstick.py @@ -71,7 +71,7 @@ def __getattribute__(self, name): if callable(attr) and not getattr(attr, "no_backend_required", False): def wrapper(*args, **kwargs): - if self.backend is None: + if not getattr(self, "backend", None): raise NotConnected("No backend set") return attr(*args, **kwargs) diff --git a/tests/clients/test_blinkstick.py b/tests/clients/test_blinkstick.py index 6ac420f..067ac7a 100644 --- a/tests/clients/test_blinkstick.py +++ b/tests/clients/test_blinkstick.py @@ -17,10 +17,11 @@ def test_instantiate(): assert bs is not None -def test_all_methods_require_backend(make_blinkstick): +def test_all_methods_require_backend(): """Test that all methods require a backend.""" - bs = make_blinkstick() - bs.backend = None # noqa + # Create an instance of BlinkStick. Note that we do not use the mock, or pass a device. + # This is deliberate, as we want to test that all methods raise an exception when the backend is not set. + bs = BlinkStick() class_methods = ( method