Skip to content

Commit cd5af92

Browse files
committed
WIP: Run thread signal test on CI
1 parent 9ccd999 commit cd5af92

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test_wait_signal.py

+40
Original file line numberDiff line numberDiff line change
@@ -1364,3 +1364,43 @@ def test_timeout_not_raising(self, qtbot):
13641364
assert not callback.called
13651365
assert callback.args is None
13661366
assert callback.kwargs is None
1367+
1368+
1369+
def test_signal_raised_from_thread(pytester: pytest.Pytester) -> None:
1370+
"""Wait for a signal with a thread.
1371+
1372+
Extracted from https://github.com/pytest-dev/pytest-qt/issues/586
1373+
"""
1374+
# Hopefully enough to trigger the bug reliably. With 500 runs, only 1 of 5
1375+
# Windows PySide6 CI jobs triggered it (but all Ubuntu/macOS jobs did).
1376+
#
1377+
# On my machine (Intel Core Ultra 9 185H), this triggers it ~50 times and
1378+
# takes ~1s in total.
1379+
count = 1500
1380+
1381+
pytester.makepyfile(f"""
1382+
import pytest
1383+
from pytestqt.qt_compat import qt_api
1384+
1385+
1386+
class Worker(qt_api.QtCore.QObject):
1387+
signal = qt_api.Signal()
1388+
1389+
1390+
@pytest.mark.parametrize("_", range({count}))
1391+
def test_thread(qtbot, _):
1392+
worker = Worker()
1393+
thread = qt_api.QtCore.QThread()
1394+
worker.moveToThread(thread)
1395+
thread.start()
1396+
1397+
try:
1398+
with qtbot.waitSignal(worker.signal, timeout=500) as blocker:
1399+
worker.signal.emit()
1400+
finally:
1401+
thread.quit()
1402+
thread.wait()
1403+
""")
1404+
1405+
res = pytester.runpytest_subprocess()
1406+
res.assert_outcomes(passed=count)

0 commit comments

Comments
 (0)