Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update app-model doc with new information about _mock_app fixture #403

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/developers/architecture/app_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,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`](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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention that it is exported just like make_napari_viewer so envs with napari installed will be able to use these fixtures? We do mention this when we talk about make_napari_viewer: https://napari.org/dev/developers/contributing/testing.html#make-napari-viewer

(ignore the failed include, I think thats fixed in #393)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it but since we've kept it private (kinda with the underscore), I'd rather not mention it explicitly as I don't necessarily want to encourage direct usage of it by external packages. If we find use for it I'd be happy to amend then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, good point.

Slightly related. could we add a link to the make_napari_viewer, maybe further up, when we first mention it?

```

The mock `app` registers non-Qt `Action`s, providers and processors. This is
Expand Down
1 change: 1 addition & 0 deletions docs/developers/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def test_something_else(qtbot):
...
```

(make_napari_viewer)=
#### `make_napari_viewer`

We provide a
Expand Down
Loading