Unitest ИзолированныеAsyncioTestCase не работаетPython

Программы на Python
Anonymous
Unitest ИзолированныеAsyncioTestCase не работает

Сообщение Anonymous »

Мне нужно использовать SiliconeAsyncioTestCase для выполнения асинхронной проверки
почему мой код не выполняется параллельно или асинхронно, мне нужно, чтобы test2
、test3、test4 запускался в асинхронном режиме
async def check_status(name:str):
print(f"before {name}")
await asyncio.sleep(5)
print(f"after {name}")
return True

class TestAsync(IsolatedAsyncioTestCase):

async def test_002(self):
print("test_002")
res = await check_status("test_002")
self.assertTrue(res)

async def test_003(self):
print("test_003")
res = await check_status("test_003")
self.assertTrue(res)

async def test_004(self):
print("test_004")
res = await check_status("test_004")
self.assertTrue(res)

if __name__ == "__main__":
unittest.main()


вот результат, все еще синхронизированный
test_002
before test_002
after test_002
test_003
before test_003
after test_003
test_004
before test_004
after test_004


Подробнее здесь: https://stackoverflow.com/questions/706 ... oesnt-work

Вернуться в «Python»