brain_unittest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
  4. """Astroid hooks for unittest module."""
  5. from astroid.brain.helpers import register_module_extender
  6. from astroid.builder import parse
  7. from astroid.const import PY38_PLUS
  8. from astroid.manager import AstroidManager
  9. def IsolatedAsyncioTestCaseImport():
  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/PyCQA/pylint/issues/4060)
  17. """
  18. return parse(
  19. """
  20. from .async_case import IsolatedAsyncioTestCase
  21. """
  22. )
  23. if PY38_PLUS:
  24. register_module_extender(
  25. AstroidManager(), "unittest", IsolatedAsyncioTestCaseImport
  26. )