{"library":"asynctest","code":"import asynctest\nimport asyncio\n\nclass MyAsyncTest(asynctest.TestCase):\n    async def my_async_function(self):\n        # Simulate an asynchronous operation\n        await asyncio.sleep(0.001)\n        return \"async_result\"\n\n    async def test_my_async_method(self):\n        result = await self.my_async_function()\n        self.assertEqual(result, \"async_result\")\n\n    async def test_with_coroutine_mock(self):\n        mock_return = \"mocked_async_data\"\n        my_mock = asynctest.CoroutineMock(return_value=mock_return)\n        \n        # Call the mocked coroutine\n        data = await my_mock()\n        \n        self.assertEqual(data, mock_return)\n        my_mock.assert_awaited_once()\n\n# To run these tests, save the file (e.g., test_my_module.py) and run:\n# python -m unittest test_my_module.py\n# asynctest.main() can also be used if explicitly desired, but unittest discovery works.","lang":"python","description":"This quickstart demonstrates how to create an asynchronous test case using `asynctest.TestCase`, defining an `async def` test method, and how to use `asynctest.CoroutineMock` to mock asynchronous functions. Tests are automatically run within their own event loop, which is managed by `asynctest`.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}