Skip to content

Commit 67fb5df

Browse files
committed
test: refactor test_all_methods_require_backend to use parameterized tests
1 parent 7d1a97d commit 67fb5df

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

tests/clients/test_blinkstick.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,30 @@
1313
from tests.conftest import make_blinkstick
1414

1515

16+
def get_blinkstick_methods():
17+
"""Get all public methods from BlinkStick class."""
18+
return [
19+
method
20+
for method in dir(BlinkStick)
21+
if callable(getattr(BlinkStick, method)) and not method.startswith("__")
22+
]
23+
24+
1625
def test_instantiate():
1726
"""Test that we can instantiate a BlinkStick object."""
1827
bs = BlinkStick()
1928
assert bs is not None
2029

2130

22-
def test_all_methods_require_backend():
31+
@pytest.mark.parametrize("method_name", get_blinkstick_methods())
32+
def test_all_methods_require_backend(method_name):
2333
"""Test that all methods require a backend."""
2434
# Create an instance of BlinkStick. Note that we do not use the mock, or pass a device.
2535
# This is deliberate, as we want to test that all methods raise an exception when the backend is not set.
2636
bs = BlinkStick()
27-
28-
class_methods = (
29-
method
30-
for method in dir(BlinkStick)
31-
if callable(getattr(bs, method)) and not method.startswith("__")
32-
)
33-
for method_name in class_methods:
34-
method = getattr(bs, method_name)
35-
with pytest.raises(NotConnected):
36-
method()
37+
method = getattr(bs, method_name)
38+
with pytest.raises(NotConnected):
39+
method()
3740

3841

3942
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)