Skip to content

Commit d0cf386

Browse files
generatedunixname893464919433493meta-codesync[bot]
authored andcommitted
Document: fbsource/py/fbcode/later.unittest.case.TestCase
Summary: ## Instructions about RACER Diffs: **Commandeer this diff (recommended) or land with accept2ship tag.** **This diff was generated by Racer AI agent on behalf of [Brian Johnson](https://www.internalfb.com/profile/view/8646079) for T246558534. If the diff quality is poor, consider contacting the user to provide clearer instructions on the task.** - If you are happy with the changes, commandeer it if minor edits are needed. (**we encourage commandeer to get the diff credit**) - If you are not happy with the changes, please comment on the diff with clear actions and send it back to the author. Racer will pick it up and re-generate. - If you really feel the Racer is not helping with this change (alas, some complex changes are hard for AI) feel free to abandon this diff. - **For M10N reviewers:** as you review AI-generated diffs, we ask you to give them the same priority as human-generated diffs, and take action in a timely manner by either accepting, rejecting, or resigning as a reviewer. For diffs that don't meet the quality bar (e.g. code doesn't compile, not readable or introduces functionality regressions), we ask that you use the following hashtags to provide clear signals to improve our tools - `#monlowqualitydiff` `#monwrongreviewerdiff` ## Summary: Added comprehensive docstring to the `later.unittest.case.TestCase` class to document its purpose, functionality, and usage patterns. The TestCase class is an enhanced async test case that extends `IsolatedAsyncioTestCase` to provide automatic tracking of asyncio tasks and monitoring of asyncio errors. The docstring includes: - Overview of the class's core functionality (task leak detection and asyncio error monitoring) - Key features: automatic detection of un-awaited tasks, monitoring of asyncio logger errors, custom task factory, and isolated event loops - Usage guidance for the `ignoreTaskLeaks` and `ignoreAsyncioErrors` decorators - Example code demonstrating typical usage patterns This documentation helps developers understand how to properly use this specialized test case for async testing while ensuring tasks are properly managed. --- > Generated by [RACER](https://www.internalfb.com/wiki/RACER_(Risk-Aware_Code_Editing_and_Refactoring)/), powered by [Confucius](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/) [Session](https://www.internalfb.com/confucius?session_id=d497aab8-cadc-11f0-9aa2-0f6362700475&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=d497aab8-cadc-11f0-9aa2-0f6362700475&tab=Trace) Reviewed By: fried Differential Revision: D87928508 fbshipit-source-id: 79ab5085735c9c9f8bb048b6a6f5c37b266c739c
1 parent a179231 commit d0cf386

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

later/unittest/case.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ def ignoreTaskLeaks(test_item: _F) -> _F:
9292

9393

9494
class TestCase(AsyncioTestCase):
95+
"""
96+
Enhanced async test case that automatically tracks asyncio tasks and monitors errors.
97+
98+
This test case extends unittest.IsolatedAsyncioTestCase to provide:
99+
- Automatic detection of un-awaited asyncio tasks, failing tests that leak tasks
100+
- Monitoring of asyncio logger errors, treating them as test failures
101+
- Custom task factory for tracking task lifecycle and management
102+
- Isolated event loop per test method for reproducible async testing
103+
104+
Use @ignoreTaskLeaks decorator on test methods that intentionally create
105+
background tasks, or @ignoreAsyncioErrors for tests expecting asyncio warnings.
106+
107+
Example:
108+
class MyAsyncTest(TestCase):
109+
async def test_async_operation(self) -> None:
110+
result = await some_async_function()
111+
self.assertEqual(result, expected_value)
112+
113+
@ignoreTaskLeaks
114+
async def test_background_task(self) -> None:
115+
asyncio.create_task(background_operation())
116+
"""
117+
95118
def _callTestMethod(self, testMethod: Callable[..., None]) -> None:
96119
ignore_error = getattr(
97120
self,

0 commit comments

Comments
 (0)