Skip to content

Commit d718fe7

Browse files
committed
Merge pull request #22 from nicoddemus/qapp-session-scoped
Qapp session scoped
2 parents 8d845a9 + 74f840f commit d718fe7

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ virtualenv:
1010
env:
1111
- PYTEST_VERSION=2.5.2 PYTEST_QT_FORCE_PYQT=true
1212
- PYTEST_VERSION=2.5.2 PYTEST_QT_FORCE_PYQT=false
13-
- PYTEST_VERSION=2.6.0 PYTEST_QT_FORCE_PYQT=true
14-
- PYTEST_VERSION=2.6.0 PYTEST_QT_FORCE_PYQT=false
13+
- PYTEST_VERSION=2.6.3 PYTEST_QT_FORCE_PYQT=true
14+
- PYTEST_VERSION=2.6.3 PYTEST_QT_FORCE_PYQT=false
1515

1616
install:
1717
- sudo apt-get update

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@ Many thanks to:
101101
- John David Reaver (`@jdreaver <https://github.com/jdreaver>`_);
102102
- Benjamin Hedrich (`@bh <https://github.com/bh>`_);
103103
- Benjamin Audren (`@baudren <https://github.com/baudren>`_);
104+
- Fabio Zadrozny (`@fabioz <https://github.com/fabioz>`_);
104105

105106
.. _tox: http://tox.readthedocs.org

pytestqt/plugin.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,6 @@ def __exit__(self, type, value, traceback):
321321
self.wait()
322322

323323

324-
def pytest_configure(config):
325-
"""
326-
PyTest plugin API. Called before the start of each test session, used
327-
to instantiate the qApplication object that will be used for the session.
328-
329-
:param config.Config config:
330-
"""
331-
qt_app_instance = QtGui.QApplication([])
332-
config.qt_app_instance = qt_app_instance
333-
334-
def exit_qapp():
335-
'''
336-
Makes sure to exit the application after all tests finish running.
337-
'''
338-
qt_app_instance.exit()
339-
340-
config._cleanup.append(exit_qapp)
341-
342-
343324
@contextmanager
344325
def capture_exceptions():
345326
"""
@@ -374,15 +355,30 @@ def format_captured_exceptions(exceptions):
374355
return message
375356

376357

358+
@pytest.yield_fixture(scope='session')
359+
def qapp():
360+
"""
361+
fixture that instantiates the QApplication instance that will be used by
362+
the tests.
363+
"""
364+
app = QtGui.QApplication.instance()
365+
if app is None:
366+
app = QtGui.QApplication([])
367+
yield app
368+
app.exit()
369+
else:
370+
yield app # pragma: no cover
371+
372+
377373
@pytest.yield_fixture
378-
def qtbot(request):
374+
def qtbot(qapp):
379375
"""
380376
Fixture used to create a QtBot instance for using during testing.
381377
382378
Make sure to call addWidget for each top-level widget you create to ensure
383379
that they are properly closed after the test ends.
384380
"""
385-
result = QtBot(request.config.qt_app_instance)
381+
result = QtBot(qapp)
386382
with capture_exceptions() as exceptions:
387383
yield result
388384

0 commit comments

Comments
 (0)