Skip to content

Commit f4cbe60

Browse files
Patch MagicMock to asyncronize
1 parent 2dc37ea commit f4cbe60

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/test_broker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import asyncio
55
import logging
66
import unittest
7-
from unittest.mock import patch, call
7+
from unittest.mock import patch, call, MagicMock
88

99
from hbmqtt.adapters import StreamReaderAdapter, StreamWriterAdapter
1010
from hbmqtt.broker import (
@@ -44,13 +44,13 @@
4444
}
4545
}
4646

47+
# monkey patch MagicMock
48+
# taken from https://stackoverflow.com/questions/51394411/python-object-magicmock-cant-be-used-in-await-expression
49+
async def async_magic():
50+
pass
51+
52+
MagicMock.__await__ = lambda x: async_magic().__await__()
4753

48-
#class AsyncMock(MagicMock):
49-
# def __await__(self, *args, **kwargs):
50-
# future = asyncio.Future()
51-
# future.set_result(self)
52-
# result = await future
53-
# return result
5454

5555
class BrokerTest(unittest.TestCase):
5656
def setUp(self):

0 commit comments

Comments
 (0)