kikocis/auto-code-rover public
| 1 | diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py |
| 2 | --- a/src/_pytest/pathlib.py |
| 3 | +++ b/src/_pytest/pathlib.py |
| 4 | @@ -523,6 +523,8 @@ def import_path( |
| 5 | |
| 6 | if mode is ImportMode.importlib: |
| 7 | module_name = module_name_from_path(path, root) |
| 8 | + with contextlib.suppress(KeyError): |
| 9 | + return sys.modules[module_name] |
| 10 | |
| 11 | for meta_importer in sys.meta_path: |
| 12 | spec = meta_importer.find_spec(module_name, [str(path.parent)]) |