Avoid using qapp with autouse=True
This commit is contained in:
parent
68af23b76e
commit
afe16d3a7c
@ -24,7 +24,6 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
import mimetypes
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import hypothesis
|
import hypothesis
|
||||||
@ -36,7 +35,6 @@ from helpers import logfail
|
|||||||
from helpers.logfail import fail_on_logging
|
from helpers.logfail import fail_on_logging
|
||||||
from helpers.messagemock import message_mock
|
from helpers.messagemock import message_mock
|
||||||
from helpers.fixtures import * # noqa: F403
|
from helpers.fixtures import * # noqa: F403
|
||||||
from qutebrowser.browser import qutescheme
|
|
||||||
from qutebrowser.utils import qtutils, standarddir, usertypes, utils, version
|
from qutebrowser.utils import qtutils, standarddir, usertypes, utils, version
|
||||||
from qutebrowser.misc import objects
|
from qutebrowser.misc import objects
|
||||||
from qutebrowser.qt import sip
|
from qutebrowser.qt import sip
|
||||||
@ -287,26 +285,3 @@ def pytest_runtest_makereport(item, call):
|
|||||||
outcome = yield
|
outcome = yield
|
||||||
rep = outcome.get_result()
|
rep = outcome.get_result()
|
||||||
setattr(item, "rep_" + rep.when, rep)
|
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
|
|
||||||
|
@ -31,6 +31,8 @@ import itertools
|
|||||||
import textwrap
|
import textwrap
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
import types
|
import types
|
||||||
|
import mimetypes
|
||||||
|
import os.path
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
import pytest
|
import pytest
|
||||||
@ -44,7 +46,7 @@ import helpers.utils
|
|||||||
from qutebrowser.config import (config, configdata, configtypes, configexc,
|
from qutebrowser.config import (config, configdata, configtypes, configexc,
|
||||||
configfiles, configcache)
|
configfiles, configcache)
|
||||||
from qutebrowser.utils import objreg, standarddir, utils, usertypes
|
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.browser.webkit import cookies
|
||||||
from qutebrowser.misc import savemanager, sql, objects
|
from qutebrowser.misc import savemanager, sql, objects
|
||||||
from qutebrowser.keyinput import modeman
|
from qutebrowser.keyinput import modeman
|
||||||
@ -152,10 +154,33 @@ def greasemonkey_manager(data_tmpdir):
|
|||||||
objreg.delete('greasemonkey')
|
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
|
@pytest.fixture
|
||||||
def webkit_tab(qtbot, tab_registry, cookiejar_and_cache, mode_manager,
|
def webkit_tab(qtbot, tab_registry, cookiejar_and_cache, mode_manager,
|
||||||
session_manager_stub, greasemonkey_manager, fake_args,
|
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
|
# Make sure error logging via JS fails tests
|
||||||
config_stub.val.content.javascript.log = {
|
config_stub.val.content.javascript.log = {
|
||||||
'info': 'info',
|
'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,
|
def webengine_tab(qtbot, tab_registry, fake_args, mode_manager,
|
||||||
session_manager_stub, greasemonkey_manager,
|
session_manager_stub, greasemonkey_manager,
|
||||||
redirect_webengine_data, tabbed_browser_stubs,
|
redirect_webengine_data, tabbed_browser_stubs,
|
||||||
config_stub, qapp):
|
config_stub, qapp, testdata_scheme):
|
||||||
# Make sure error logging via JS fails tests
|
# Make sure error logging via JS fails tests
|
||||||
config_stub.val.content.javascript.log = {
|
config_stub.val.content.javascript.log = {
|
||||||
'info': 'info',
|
'info': 'info',
|
||||||
|
Loading…
Reference in New Issue
Block a user