1# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
2# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
3# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
4
5"""Astroid hooks for unittest module."""
6
7from astroid import nodes
8from astroid.brain.helpers import register_module_extender
9from astroid.builder import parse
10from astroid.manager import AstroidManager
11
12
13def IsolatedAsyncioTestCaseImport() -> nodes.Module:
14 """
15 In the unittest package, the IsolatedAsyncioTestCase class is imported lazily.
16
17 I.E. only when the ``__getattr__`` method of the unittest module is called with
18 'IsolatedAsyncioTestCase' as argument. Thus the IsolatedAsyncioTestCase
19 is not imported statically (during import time).
20 This function mocks a classical static import of the IsolatedAsyncioTestCase.
21
22 (see https://github.com/pylint-dev/pylint/issues/4060)
23 """
24 return parse("""
25 from .async_case import IsolatedAsyncioTestCase
26 """)
27
28
29def register(manager: AstroidManager) -> None:
30 register_module_extender(manager, "unittest", IsolatedAsyncioTestCaseImport)