Skip to content

Commit 55613d0

Browse files
edersondisouzanashif
authored andcommitted
twister/pytest: Add unlaunched_dut fixture
Add a new fixture, `unlaunched_dut`, which is basically the `dut` one, but without launching the device - thus also not building the application. It is useful for tests who need a finer control of the building of the application, before the dut can be launched to run it. It will be used on a future patch, which will use it to enable LLEXT EDK tests. Signed-off-by: Ederson de Souza <[email protected]>
1 parent e4cc0f2 commit 55613d0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

doc/develop/test/pytest.rst

+16
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ a fixture ``mcumgr``
166166
mcumgr.reset_device()
167167
# continue test scenario, check version etc.
168168
169+
170+
unlauched_dut
171+
=============
172+
173+
Similar to the ``dut`` fixture, but it does not initialize the device. It can be used when a finer
174+
control over the build process is needed. It becomes responsibility of the test to initialize the
175+
device.
176+
177+
.. code-block:: python
178+
179+
from twister_harness import DeviceAdapter
180+
181+
def test_sample(unlauched_dut: DeviceAdapter):
182+
unlaunched_dut.launch()
183+
unlaunched_dut.readlines_until('Hello world')
184+
169185
Classes
170186
*******
171187

scripts/pylib/pytest-twister-harness/src/twister_harness/fixtures.py

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ def determine_scope(fixture_name, config):
4545
return 'function'
4646

4747

48+
@pytest.fixture(scope=determine_scope)
49+
def unlaunched_dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generator[DeviceAdapter, None, None]:
50+
"""Return device object - with logs connected, but not run"""
51+
device_object.initialize_log_files(request.node.name)
52+
try:
53+
yield device_object
54+
finally: # to make sure we close all running processes execution
55+
device_object.close()
56+
4857
@pytest.fixture(scope=determine_scope)
4958
def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generator[DeviceAdapter, None, None]:
5059
"""Return launched device - with run application."""

0 commit comments

Comments
 (0)