Skip to content
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
17 changes: 10 additions & 7 deletions pytest-embedded/pytest_embedded/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


##################
Expand Down
15 changes: 11 additions & 4 deletions pytest-embedded/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down