brain_unittest.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  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. """Astroid hooks for unittest module."""
  5. from astroid import nodes
  6. from astroid.brain.helpers import register_module_extender
  7. from astroid.builder import parse
  8. from astroid.manager import AstroidManager
  9. def IsolatedAsyncioTestCaseImport() -> nodes.Module:
  10. """
  11. In the unittest package, the IsolatedAsyncioTestCase class is imported lazily.
  12. I.E. only when the ``__getattr__`` method of the unittest module is called with
  13. 'IsolatedAsyncioTestCase' as argument. Thus the IsolatedAsyncioTestCase
  14. is not imported statically (during import time).
  15. This function mocks a classical static import of the IsolatedAsyncioTestCase.
  16. (see https://github.com/pylint-dev/pylint/issues/4060)
  17. """
  18. return parse(
  19. """
  20. from .async_case import IsolatedAsyncioTestCase
  21. """
  22. )
  23. def register(manager: AstroidManager) -> None:
  24. register_module_extender(manager, "unittest", IsolatedAsyncioTestCaseImport)