Skip to content

tests: refactor the Qt test harness to support running QObject's within a QCoreApplication#10699

Open
accumulator wants to merge 3 commits into
spesmilo:masterfrom
accumulator:qobject_test_harness
Open

tests: refactor the Qt test harness to support running QObject's within a QCoreApplication#10699
accumulator wants to merge 3 commits into
spesmilo:masterfrom
accumulator:qobject_test_harness

Conversation

@accumulator

Copy link
Copy Markdown
Member

tests: refactor the Qt test harness to support running QObject's within a QCoreApplication and its event
loop, so we can fully test behaviour with more complex QObject hierarchies and check for signal emits.

adds some initial tests for QEWallet

@accumulator

Copy link
Copy Markdown
Member Author

Interesting. These new Qt testcases unearthed a pre-existing bug.

FAILED tests/test_daemon.py::TestUnifiedPassword::test_wallet_objects_are_properly_garbage_collected_after_check_pw_for_dir - AssertionError: 2 != 0 : too many lingering objs of type=<class 'electrum.wallet.Abstract_Wallet'>

There are some lifecycle issues with some QObject subclasses (in particular QEWallet), where strong references are kept, even after these objects are supposedly deleted. There's tension between the PyQt wrappers and the underlying Qt C++ objects, either side can initiate destruction, both must be correctly handled.

I'll submit fixes in another PR.

…in a QCoreApplication and its event

loop, so we can fully test behaviour with more complex QObject hierarchies and check for signal emits

add some initial tests for QEWallet
A qt_test body runs inside app.exec() (one loop level deep, via doInvoke),
so a QObject.deleteLater() posted there is never delivered by processEvents()
-- Qt only delivers DeferredDelete once the loop unwinds to the level at which
it was posted. The C++ objects, and everything they reference (e.g. a
QEWallet's self.wallet), lingered until some later, racy spin of the loop.

Flush them synchronously via sendPostedEvents(None, DeferredDelete), then
gc.collect() so reference cycles (e.g. wallet<->txbatcher) are reclaimed and
their EventListener.__del__ unregisters callbacks. This keeps QML tests from
leaking wallet objects and callbacks into later tests (e.g. test_daemon's GC
sanity checks).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@accumulator accumulator force-pushed the qobject_test_harness branch from bfb1569 to ba358b1 Compare June 12, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant