用法:
class unittest.IsolatedAsyncioTestCase(methodName='runTest')
此類提供類似於
TestCase
的 API,並且還接受協程作為測試函數。3.8 版中的新函數。
說明順序的示例:
from unittest import IsolatedAsyncioTestCase events = [] class Test(IsolatedAsyncioTestCase): def setUp(self): events.append("setUp") async def asyncSetUp(self): self._async_connection = await AsyncConnection() events.append("asyncSetUp") async def test_response(self): events.append("test_response") response = await self._async_connection.get("https://example.com") self.assertEqual(response.status_code, 200) self.addAsyncCleanup(self.on_cleanup) def tearDown(self): events.append("tearDown") async def asyncTearDown(self): await self._async_connection.close() events.append("asyncTearDown") async def on_cleanup(self): events.append("cleanup") if __name__ == "__main__": unittest.main()
運行測試後,
events
將包含["setUp", "asyncSetUp", "test_response", "asyncTearDown", "tearDown", "cleanup"]
。
相關用法
- Python unittest.mock.AsyncMock.assert_awaited_once_with用法及代碼示例
- Python unittest.TestCase.assertWarnsRegex用法及代碼示例
- Python unittest.mock.Mock.reset_mock用法及代碼示例
- Python unittest.mock.Mock.__class__用法及代碼示例
- Python unittest.mock.Mock.call_args用法及代碼示例
- Python unittest.TestCase.assertRaisesRegex用法及代碼示例
- Python unittest.mock.call用法及代碼示例
- Python unittest.mock.Mock.method_calls用法及代碼示例
- Python unittest.mock.Mock.call_args_list用法及代碼示例
- Python unittest.mock.AsyncMock.assert_any_await用法及代碼示例
- Python unittest.mock.Mock.assert_called用法及代碼示例
- Python unittest.TestCase.assertRaises用法及代碼示例
- Python unittest.TestCase.tearDownClass用法及代碼示例
- Python unittest.mock.Mock.assert_not_called用法及代碼示例
- Python unittest.TestCase.setUpClass用法及代碼示例
- Python unittest.mock.AsyncMock.await_args_list用法及代碼示例
- Python unittest.mock.Mock.mock_calls用法及代碼示例
- Python unittest.mock.Mock.assert_has_calls用法及代碼示例
- Python unittest.mock.AsyncMock.assert_awaited_with用法及代碼示例
- Python unittest.mock.Mock.configure_mock用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 unittest.IsolatedAsyncioTestCase。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。