Skip to content

Commit d369b3c

Browse files
committed
Split documentation into multiple rst documents
1 parent 9fa04b5 commit d369b3c

File tree

8 files changed

+527
-523
lines changed

8 files changed

+527
-523
lines changed

docs/app_exit.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
A note about QApplication.exit()
2+
================================
3+
4+
Some ``pytest-qt`` features, most notably ``waitSignal`` and ``waitSignals``,
5+
depend on the Qt event loop being active. Calling ``QApplication.exit()``
6+
from a test will cause the main event loop and auxiliary event loops to
7+
exit and all subsequent event loops to fail to start. This is a problem if some
8+
of your tests call an application functionality that calls
9+
``QApplication.exit()``.
10+
11+
One solution is to *monkeypatch* ``QApplication.exit()`` in such tests to ensure
12+
it was called by the application code but without effectively calling it.
13+
14+
For example:
15+
16+
.. code-block:: python
17+
18+
def test_exit_button(qtbot, monkeypatch):
19+
exit_calls = []
20+
monkeypatch.setattr(QApplication, 'exit', lambda: exit_calls.append(1))
21+
button = get_app_exit_button()
22+
qtbot.click(button)
23+
assert exit_calls == [1]
24+
25+
26+
Or using the ``mock`` package:
27+
28+
.. code-block:: python
29+
30+
def test_exit_button(qtbot):
31+
with mock.patch.object(QApplication, 'exit'):
32+
button = get_app_exit_button()
33+
qtbot.click(button)
34+
assert QApplication.exit.call_count == 1
35+

0 commit comments

Comments
 (0)