diff --git a/pytest-embedded/pytest_embedded/plugin.py b/pytest-embedded/pytest_embedded/plugin.py index 70af0d45..d6c27029 100644 --- a/pytest-embedded/pytest_embedded/plugin.py +++ b/pytest-embedded/pytest_embedded/plugin.py @@ -1349,16 +1349,19 @@ def dut( @pytest.fixture def unity_tester(dut: t.Union['IdfDut', tuple['IdfDut']]) -> t.Optional['CaseTester']: try: - from pytest_embedded_idf import CaseTester, IdfDut + from pytest_embedded_idf import CaseTester + from pytest_embedded_idf.unity_tester import IdfUnityDutMixin except ImportError: yield None else: - # all dut instance must be IdfDut to use this fixture - for _dut in to_list(dut): - if not isinstance(_dut, IdfDut): - yield None - - yield CaseTester(to_list(dut)) + duts = to_list(dut) + # `CaseTester` drives the unity test menu, which every dut carrying + # `IdfUnityDutMixin` provides: `IdfDut` inherits it, and the dut factory + # mixes it into the qemu and esp-emu duts when the idf service is used. + if all(isinstance(_dut, IdfUnityDutMixin) for _dut in duts): + yield CaseTester(duts) + else: + yield None ################## diff --git a/pytest-embedded/tests/test_base.py b/pytest-embedded/tests/test_base.py index ede8d19c..361baaec 100644 --- a/pytest-embedded/tests/test_base.py +++ b/pytest-embedded/tests/test_base.py @@ -334,20 +334,27 @@ def test_expect_exact_no_matching_word_pass_rest(dut): def test_expect_from_timeout(testdir): testdir.makepyfile(r""" import threading - import time import pexpect def test_expect_from_timeout(msg_queue, dut): + stop = threading.Event() + def write_bytes(): for _ in range(5): + if stop.is_set(): + return msg_queue.write('1') - time.sleep(1.5) + stop.wait(1.5) write_thread = threading.Thread(target=write_bytes, daemon=True) write_thread.start() - res = dut.expect(pexpect.TIMEOUT, timeout=4) - assert res == b'111' + try: + res = dut.expect(pexpect.TIMEOUT, timeout=4) + assert res == b'111' + finally: + stop.set() + write_thread.join(timeout=2) """) result = testdir.runpytest('-s')