Search code examples
pythonmockingstubmodulenotfounderror

how can I mock Python "ModuleNotFoundError"


I am testing part of the project, I have a ModuleNotFoundError as the module is in another part of the project that is not accessible, I can comment, but in the testing phase I would like to stub.


Solution

  • Found a solution that works for me

    from unittest.mock import MagicMock
    sys.modules['module_name'] = MagicMock()