@@ -49,7 +49,7 @@ def __init__(self, options: Options):
4949 # Without require_module, our _set_collections_basedir may fail
5050 self .runtime = Runtime (
5151 project_dir = Path (options .project_dir ),
52- isolated = True ,
52+ isolated = not options . offline ,
5353 require_module = True ,
5454 verbosity = options .verbosity ,
5555 )
@@ -403,6 +403,19 @@ def _add_collections_path_if_needed(
403403 collections_paths .insert (0 , str (mock_path ))
404404
405405
406+ def _add_module_path_if_needed (
407+ options : Options ,
408+ module_paths : list [str ],
409+ ) -> None :
410+ """Add plain mock modules path to module_paths if module mocks exist."""
411+ if options .cache_dir and any (
412+ len (module_name .split ("." )) < 3 for module_name in options .mock_modules
413+ ):
414+ mock_path = options .cache_dir / "modules"
415+ if str (mock_path ) not in module_paths :
416+ module_paths .insert (0 , str (mock_path ))
417+
418+
406419def get_app (* , offline : bool | None = None , cached : bool = False ) -> App :
407420 """Return the application instance, caching the return value."""
408421 # Avoids ever running the app initialization twice if cached argument
@@ -445,6 +458,7 @@ def get_app(*, offline: bool | None = None, cached: bool = False) -> App:
445458
446459 # https://github.com/ansible/ansible-lint/issues/4973
447460 _add_collections_path_if_needed (app .options , app .runtime .config .collections_paths )
461+ _add_module_path_if_needed (app .options , app .runtime .config .default_module_path )
448462
449463 app .runtime .prepare_environment (
450464 install_local = (not offline ),
0 commit comments