From e44d0f2f0a9e49dd410406c8610b145cc742648a Mon Sep 17 00:00:00 2001 From: Draga Doncila Date: Fri, 12 Apr 2024 16:56:33 +1000 Subject: [PATCH 1/2] Update app-model doc --- docs/developers/architecture/app_model.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/developers/architecture/app_model.md b/docs/developers/architecture/app_model.md index 0fc48d9e..a95d12f2 100644 --- a/docs/developers/architecture/app_model.md +++ b/docs/developers/architecture/app_model.md @@ -482,16 +482,17 @@ Segmentation faults can also occur as a singleton `app` may keep a reference to an object, e.g., a {class}`~napari._qt.qt_main_window.Window`, that has since been cleaned up at the end of a previous test. -Thus, we mock the `app` in a `_mock_app` fixture and -[autouse](https://docs.pytest.org/en/latest/how-to/fixtures.html#autouse-fixtures-fixtures-you-don-t-have-to-request) -it so a new instance of `app` is returned every time {func}`~napari._app_model.get_app` +Thus, we mock the `app` in a `_mock_app` fixture, and +explicitly use it in `make_napari_viewer` as well as in all tests that +use the `get_app` function. This way, a new instance of `app` is returned +every time {func}`~napari._app_model.get_app` is used inside a test. This 'test' `app` is available for use throughout the test's duration and will get cleaned up at the end. ```{note} -Since the `_mock_app` fixture is autouse, a -:class:`~napari._app_model._app.NapariApplication` is instantiated during setup -of every test. +Since the `_mock_app` fixture is used in `make_napari_viewer`, plugins and other +external users that write tests using `make_napari_viewer` will also have the benefit +of a new app for each test. ``` The mock `app` registers non-Qt `Action`s, providers and processors. This is From 574f341243882e588c455cc2f73aea967eec7ce9 Mon Sep 17 00:00:00 2001 From: Draga Doncila Pop Date: Wed, 17 Apr 2024 15:00:08 +1000 Subject: [PATCH 2/2] Add make_napari_viewer cross ref --- docs/developers/architecture/app_model.md | 2 +- docs/developers/contributing/testing.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/developers/architecture/app_model.md b/docs/developers/architecture/app_model.md index 2267cd02..e76e1800 100644 --- a/docs/developers/architecture/app_model.md +++ b/docs/developers/architecture/app_model.md @@ -485,7 +485,7 @@ singleton `app` may keep a reference to an object, e.g., a {class}`~napari._qt.qt_main_window.Window`, that has since been cleaned up at the end of a previous test. Thus, we mock the `app` in a `_mock_app` fixture, and -explicitly use it in `make_napari_viewer` as well as in all tests that +explicitly use it in [`make_napari_viewer`](make_napari_viewer) as well as in all tests that use the `get_app` function. This way, a new instance of `app` is returned every time {func}`~napari._app_model.get_app` is used inside a test. This 'test' `app` is available for use throughout the test's diff --git a/docs/developers/contributing/testing.md b/docs/developers/contributing/testing.md index 174eaadf..2e9b9320 100644 --- a/docs/developers/contributing/testing.md +++ b/docs/developers/contributing/testing.md @@ -240,6 +240,7 @@ def test_something_else(qtbot): ... ``` +(make_napari_viewer)= #### `make_napari_viewer` We provide a