Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
  • Loading branch information
Czaki and melissawm authored Oct 25, 2024
1 parent 80747bd commit e802a19
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions docs/developers/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,14 @@ def test_something_else(qtbot):
(qt_viewer)=
#### `qt_viewer` and `viewer_model`
For the test that are using only `ViewerModel` api or are only checking
rendering of the viewer, since `napari==0.5.4` we have implemented the `qt_viewer` [pytest fixture](https://docs.pytest.org/en/stable/explanation/fixtures.html).
Since `napari==0.5.4` we have implemented the `qt_viewer` [pytest fixture](https://docs.pytest.org/en/stable/explanation/fixtures.html) which can be used for tests that are only using the `ViewerModel` api or are only checking rendering of the viewer.
For the current moment, it is only for internal use and is not exported to the global scope,
as it is defined in `conftest.py` file.
The `qt_viewer` fixture return the instance of {class}`~napari.qt.QtViewer` class.
This class do not provide the same api as the {class}`~napari.ViewerModel` class,
but have associated {class}`~napari.ViewerModel` instance, which can be accessed by `viewer` attribute.
Alternatively you could use `viewer_model` fixture, which return this instance of {class}`~napari.ViewerModel` class.
The `qt_viewer` fixture returns the instance of the {class}`~napari.qt.QtViewer` class.
This class does not provide the same api as the {class}`~napari.ViewerModel` class,
but has an associated {class}`~napari.ViewerModel` instance, which can be accessed by the `viewer` attribute.
Alternatively, you could use the `viewer_model` fixture, which returns this instance of {class}`~napari.ViewerModel` class.
```python
def test_something(qt_viewer):
Expand All @@ -288,8 +287,8 @@ def test_something(qt_viewer, viewer_model):
assert viewer.layers[0].name == 'Image'
```
The `qt_viewer` fixture take care about proper teardown of all qt widgets related to the viewer.
If you need to adjust the QtViewer for a given [test file](https://docs.pytest.org/en/stable/how-to/fixtures.html#override-a-fixture-on-a-test-module-level) you can use `qt_viewer_` fixture.
The `qt_viewer` fixture takes care of proper teardown of all qt widgets related to the viewer.
If you need to adjust the QtViewer for a given [test file](https://docs.pytest.org/en/stable/how-to/fixtures.html#override-a-fixture-on-a-test-module-level) you can use the `qt_viewer_` fixture.
```python
@pytest.fixture
Expand All @@ -314,9 +313,9 @@ def qt_viewer(qt_viewer_):
(make_napari_viewer)=
#### `make_napari_viewer`
For more complex test cases where we need to test fully application behaviour
(for example using `viewer.window` API) we can use `make_napari_viewer` [pytest fixture](https://docs.pytest.org/en/stable/explanation/fixtures.html).
However, the creating and teardown of the whole viewer is more fragile and slower than using just `qt_viewer` fixture.
For more complex test cases where we need to fully test application behaviour
(for example, using the `viewer.window` API) we can use `make_napari_viewer` [pytest fixture](https://docs.pytest.org/en/stable/explanation/fixtures.html).
However, the creating and teardown of the whole viewer is more fragile and slower than using just the `qt_viewer` fixture.
This fixture is available globally and to all tests in the same environment that `napari`
is in (see [](test-organization) for details). Thus, there is no need to import it,
you simply include `make_napari_viewer` as a test function parameter, as shown in the
Expand Down

0 comments on commit e802a19

Please sign in to comment.