Avoid using qapp with autouse=True

This commit is contained in:
Florian Bruhin 2018-09-13 22:49:25 +02:00
parent 68af23b76e
commit afe16d3a7c
2 changed files with 28 additions and 28 deletions

View File

@ -24,7 +24,6 @@
import os
import sys
import warnings
import mimetypes
import pytest
import hypothesis
@ -36,7 +35,6 @@ from helpers import logfail
from helpers.logfail import fail_on_logging
from helpers.messagemock import message_mock
from helpers.fixtures import * # noqa: F403
from qutebrowser.browser import qutescheme
from qutebrowser.utils import qtutils, standarddir, usertypes, utils, version
from qutebrowser.misc import objects
from qutebrowser.qt import sip
@ -287,26 +285,3 @@ def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
@pytest.fixture(scope='session', autouse=True)
def register_testdata_scheme_handler(qapp, request):
try:
global _qute_scheme_handler
from qutebrowser.browser.webengine import webenginequtescheme
from PyQt5.QtWebEngineWidgets import QWebEngineProfile
_qute_scheme_handler = webenginequtescheme.QuteSchemeHandler(parent=qapp)
_qute_scheme_handler.install(QWebEngineProfile.defaultProfile())
except ImportError:
pass
@qutescheme.add_handler('testdata')
def handler(url):
file_abs = os.path.abspath(os.path.dirname(__file__))
filename = os.path.join(file_abs, 'end2end',
url.path().lstrip('/'))
with open(filename, 'rb') as f:
data = f.read()
mimetype, _encoding = mimetypes.guess_type(filename)
return mimetype, data

View File

@ -31,6 +31,8 @@ import itertools
import textwrap
import unittest.mock
import types
import mimetypes
import os.path
import attr
import pytest
@ -44,7 +46,7 @@ import helpers.utils
from qutebrowser.config import (config, configdata, configtypes, configexc,
configfiles, configcache)
from qutebrowser.utils import objreg, standarddir, utils, usertypes
from qutebrowser.browser import greasemonkey, history
from qutebrowser.browser import greasemonkey, history, qutescheme
from qutebrowser.browser.webkit import cookies
from qutebrowser.misc import savemanager, sql, objects
from qutebrowser.keyinput import modeman
@ -152,10 +154,33 @@ def greasemonkey_manager(data_tmpdir):
objreg.delete('greasemonkey')
@pytest.fixture(scope='session')
def testdata_scheme(qapp):
try:
global _qute_scheme_handler
from qutebrowser.browser.webengine import webenginequtescheme
from PyQt5.QtWebEngineWidgets import QWebEngineProfile
_qute_scheme_handler = webenginequtescheme.QuteSchemeHandler(parent=qapp)
_qute_scheme_handler.install(QWebEngineProfile.defaultProfile())
except ImportError:
pass
@qutescheme.add_handler('testdata')
def handler(url):
file_abs = os.path.abspath(os.path.dirname(__file__))
filename = os.path.join(file_abs, '..', 'end2end',
url.path().lstrip('/'))
with open(filename, 'rb') as f:
data = f.read()
mimetype, _encoding = mimetypes.guess_type(filename)
return mimetype, data
@pytest.fixture
def webkit_tab(qtbot, tab_registry, cookiejar_and_cache, mode_manager,
session_manager_stub, greasemonkey_manager, fake_args,
host_blocker_stub, config_stub):
host_blocker_stub, config_stub, testdata_scheme):
# Make sure error logging via JS fails tests
config_stub.val.content.javascript.log = {
'info': 'info',
@ -186,7 +211,7 @@ def webkit_tab(qtbot, tab_registry, cookiejar_and_cache, mode_manager,
def webengine_tab(qtbot, tab_registry, fake_args, mode_manager,
session_manager_stub, greasemonkey_manager,
redirect_webengine_data, tabbed_browser_stubs,
config_stub, qapp):
config_stub, qapp, testdata_scheme):
# Make sure error logging via JS fails tests
config_stub.val.content.javascript.log = {
'info': 'info',