diff --git a/pytest_anki/_launch.py b/pytest_anki/_launch.py index 8592675..11d4461 100644 --- a/pytest_anki/_launch.py +++ b/pytest_anki/_launch.py @@ -104,6 +104,7 @@ def anki_running( unpacked_addons: Optional[List[Tuple[str, PathLike]]] = None, addon_configs: Optional[List[Tuple[str, Dict[str, Any]]]] = None, enable_web_debugging: bool = True, + skip_loading_addons: bool = False, ) -> Iterator[AnkiSession]: """Context manager that safely launches an Anki session, cleaning up after itself @@ -157,6 +158,10 @@ def anki_running( If specified, launches Anki with QTWEBENGINE_REMOTE_DEBUGGING set, allowing you to remotely debug Qt web engine views. + skip_loading_addons {bool}: + If set to True, will skip loading packed and unpacked add-ons, giving the + caller full control over the add-on import time. + Returns: Iterator[AnkiSession] -- [description] @@ -178,6 +183,7 @@ def anki_running( unpacked_addons=unpacked_addons, addon_configs=addon_configs, preset_anki_state=preset_anki_state, + skip_loading_addons=skip_loading_addons, ) # Apply preset Anki profile and collection.conf storage on profile load diff --git a/pytest_anki/_patch.py b/pytest_anki/_patch.py index 4c2d12d..c0ccb5a 100644 --- a/pytest_anki/_patch.py +++ b/pytest_anki/_patch.py @@ -65,6 +65,7 @@ def post_ui_setup_callback_factory( unpacked_addons: Optional[List[Tuple[str, PathLike]]] = None, addon_configs: Optional[List[Tuple[str, Dict[str, Any]]]] = None, preset_anki_state: Optional[AnkiStateUpdate] = None, + skip_loading_addons: bool = False, ): def post_ui_setup_callback(main_window: AnkiQt): """Initialize add-on manager, install add-ons, load add-ons""" @@ -97,7 +98,8 @@ def post_ui_setup_callback(main_window: AnkiQt): main_window=main_window, anki_state_update=preset_anki_state ) - main_window.addonManager.loadAddons() + if not skip_loading_addons: + main_window.addonManager.loadAddons() return post_ui_setup_callback diff --git a/pytest_anki/plugin.py b/pytest_anki/plugin.py index 60c7d36..bf15d60 100644 --- a/pytest_anki/plugin.py +++ b/pytest_anki/plugin.py @@ -120,6 +120,9 @@ def anki_session(request: "FixtureRequest", qtbot: "QtBot") -> Iterator[AnkiSess If specified, launches Anki with QTWEBENGINE_REMOTE_DEBUGGING set, allowing you to remotely debug Qt web engine views. + skip_loading_addons {bool}: + If set to True, will skip loading packed and unpacked add-ons, giving the + caller full control over the add-on import time. """ indirect_parameters: Optional[Dict[str, Any]] = getattr(request, "param", None)