deasync decorator使异步函数/方法同步。
deasync的Python项目详细描述
deasync为python 3.5(或更高版本)提供了一个名为deasync的装饰器,使异步函数在只需要同步函数的地方同步,例如在unittest.testcase中
fromasyncioimportsleepfromunittestimportTestCasefromdeasyncimportdeasyncasyncdeffunction42():awaitsleep(0.001)return42classTestFunction42(TestCase):@deasyncasyncdeftest_function42(self):result=awaitfunction42()self.assertEquals(42,result)