brain_unittest.py 907 B

123456789101112131415161718192021222324252627
  1. """Astroid hooks for unittest module"""
  2. from astroid.brain.helpers import register_module_extender
  3. from astroid.builder import parse
  4. from astroid.const import PY38_PLUS
  5. from astroid.manager import AstroidManager
  6. def IsolatedAsyncioTestCaseImport():
  7. """
  8. In the unittest package, the IsolatedAsyncioTestCase class is imported lazily, i.e only
  9. when the __getattr__ method of the unittest module is called with 'IsolatedAsyncioTestCase' as
  10. argument. Thus the IsolatedAsyncioTestCase is not imported statically (during import time).
  11. This function mocks a classical static import of the IsolatedAsyncioTestCase.
  12. (see https://github.com/PyCQA/pylint/issues/4060)
  13. """
  14. return parse(
  15. """
  16. from .async_case import IsolatedAsyncioTestCase
  17. """
  18. )
  19. if PY38_PLUS:
  20. register_module_extender(
  21. AstroidManager(), "unittest", IsolatedAsyncioTestCaseImport
  22. )