You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removes the mention of creating the event loop as this is now automatic (#1638)
* Removes the mention of creating the event loop as this is now automatic
* Fix typo
Co-authored-by: oliwenmandiamond <[email protected]>
---------
Co-authored-by: oliwenmandiamond <[email protected]>
Copy file name to clipboardExpand all lines: docs/how-to/write-tests.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,9 +58,11 @@ class MyDevice(StandardReadable, Stageable):
58
58
59
59
In this example, we need to test the `stage` and `unstage` methods. For more complex devices, it is also a good idea to test the `read` method to confirm that we get the expected read signals back when this method is called.
60
60
61
-
We use [pytest](https://docs.pytest.org/en/stable/contents.html) for writing tests in dodal. A core part of this library is the use of fixtures. A fixture is a function decorated with `@pytest.fixture` that provides setup/teardown or reusable test data for your tests. It is defined once and can be reused across multiple tests. Fixtures are mainly used to define devices and then inject them into each test.
61
+
We use [pytest](https://docs.pytest.org/en/stable/contents.html) for writing tests in dodal. A core part of this library is the use of fixtures. A fixture is a function decorated with `@pytest.fixture` that provides setup/teardown or reusable test data for your tests. It is defined once and can be reused across multiple tests. Fixtures are mainly used to define devices and then inject them into each test.
62
62
63
-
To help set up a device, they are created with the `init_devices(mock=True)` function from `ophyd_async.core`, which automatically initialises the device in mock mode. The `RunEngine` fixture is passed when creating a device to ensure there is an event loop available when connecting signals. This fixture is defined in `dodal/tests/conftest.py`, which is a special file recognised by `pytest`. It defines fixtures that are automatically available to any test in the same directory (and its subdirectories) without needing to import them. This is useful for defining common setup code once without duplicating it across test files.
63
+
Common fixtures, such as the `run_engine` used in the below tests, can also be defined in `dodal/tests/conftest.py`, which is a special file recognised by `pytest`. These fixtures are automatically available to any test in the same directory (and its subdirectories) without needing to import them. This is useful for defining common setup code once without duplicating it across test files.
64
+
65
+
Devices are set up in the fixture using the `init_devices(mock=True)` function from `ophyd_async.core`, which automatically initialises the device in mock mode.
64
66
65
67
In order for `pytest` to detect something as a test, a function should begin with `test_*`. The test function should be self-descriptive about what it is testing, and it is acceptable (even encouraged) to have longer names for test functions for clarity.
66
68
@@ -75,9 +77,8 @@ from ophyd_async.testing import assert_reading, get_mock_put, partial_reading
75
77
from dodal.device.my_device import MyDevice
76
78
77
79
78
-
# RunEngine is needed to make sure there is an event loop when creating device.
You should test the output of a device when the device has many signals read and you want to ensure the correct ones are read at the correct times, or when the `read` method of it or one of its signals (e.g. a DerivedSignal) requires testing. Functions are defined in `ophyd-async` to aid with this. `assert_reading` allows us to compare the readings generated from a `Readable` device to the expected results.
0 commit comments