Skip to content

Commit 1820505

Browse files
committed
test: make retry wrapper async
1 parent f97e4fb commit 1820505

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

tests/unit/test_tion.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
pytest.param(2, 2, 1, 2, id="Delay between retries"),
2424
]
2525
)
26-
def test_retry(retries: int, repeats: int, succeed_run: int, t_delay: int):
26+
async def test_retry(retries: int, repeats: int, succeed_run: int, t_delay: int):
2727
class TestRetry:
2828
count = 0
2929

@@ -61,42 +61,45 @@ def setUp(self):
6161
tion_btle.tion._LOGGER.warning = mock.MagicMock(name='method')
6262
tion_btle.tion._LOGGER.critical = mock.MagicMock(name='method')
6363

64-
def test_debug_log_level(self):
64+
@pytest.mark.asyncio
65+
async def test_debug_log_level(self):
6566
@retry(retries=0)
66-
def debug():
67+
async def debug():
6768
pass
6869

6970
with mock.patch('tion_btle.tion._LOGGER') as log_mock:
70-
debug()
71+
await debug()
7172
log_mock.debug.assert_called()
7273
log_mock.info.assert_not_called()
7374
log_mock.warning.assert_not_called()
7475
log_mock.critical.assert_not_called()
7576

76-
def test_warning_log_level(self):
77+
@pytest.mark.asyncio
78+
async def test_warning_log_level(self):
7779
"""Make sure that we have warnings for exception, but have no critical if all goes well finally"""
7880
@retry(retries=1)
79-
def warning():
81+
async def warning():
8082
if self.count == 0:
8183
self.count += 1
8284
raise exc.BleakError
8385
else:
8486
pass
8587

8688
with mock.patch('tion_btle.tion._LOGGER') as log_mock:
87-
warning()
89+
await warning()
8890
log_mock.warning.assert_called()
8991
log_mock.critical.assert_not_called()
9092

91-
def test_critical_log_level(self):
93+
@pytest.mark.asyncio
94+
async def test_critical_log_level(self):
9295
"""Make sure that we have message at critical level if all goes bad"""
9396
@retry(retries=0)
94-
def critical():
97+
async def critical():
9598
raise exc.BleakError
9699

97100
with mock.patch('tion_btle.tion._LOGGER.critical') as log_mock:
98101
try:
99-
critical()
102+
await critical()
100103
except MaxTriesExceededError:
101104
pass
102105
log_mock.assert_called()

0 commit comments

Comments
 (0)