summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Albrecht <philipp.albrecht@momox.biz>2021-11-12 16:19:22 +0100
committerPhilipp Albrecht <philipp.albrecht@momox.biz>2021-11-12 16:19:22 +0100
commit256900b87a96485d7658ee26df8c96c16559eb0f (patch)
tree51bed54f0926561ceb8e4f343b8bed13834c3b23
parent59054e48b953bede603b2052c96a6d7de78abc7d (diff)
downloadqutebrowser-256900b87a96485d7658ee26df8c96c16559eb0f.tar.gz
qutebrowser-256900b87a96485d7658ee26df8c96c16559eb0f.zip
Extract backend selection into functions
In order to fix the issue of silently using QtWebEngine when e.g. --qute-bdd-backend=webkit is given, even though QtWebEngine is not available, I moved the selection logic into separate functions to clear things up a little. I tried to avoid the duplicate imports, in case the backend is auto-selected, but after a while of thinking I abandoned that idea in favor of moving forward with this.
-rw-r--r--tests/conftest.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 840ae3752..e1787fc83 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -219,23 +219,39 @@ def pytest_addoption(parser):
def pytest_configure(config):
+ backend = _select_backend(config)
+ config.webengine = backend == 'webengine'
+
+ earlyinit.configure_pyqt()
+
+
+def _select_backend(config):
+ backend_arg = config.getoption('--qute-bdd-backend')
+ backend_env = os.environ.get('QUTE_BDD_BACKEND')
+
+ backend = backend_arg or backend_env or _auto_select_backend()
+
+ # Fail early if selected backend is not available
+ if backend == 'webkit':
+ import PyQt5.QtWebKitWidgets
+ elif backend == 'webengine':
+ import PyQt5.QtWebEngineWidgets
+ else:
+ raise utils.Unreachable(backend)
+
+ return backend
+
+
+def _auto_select_backend():
try:
# Try to use QtWebKit as the default backend
import PyQt5.QtWebKitWidgets
- config.backend = 'webkit'
+ return 'webkit'
except ImportError:
# Try to use QtWebEngine as a fallback and fail early
# if that's also not available
import PyQt5.QtWebEngineWidgets
- config.backend = 'webengine'
-
- backend_arg = config.getoption('--qute-bdd-backend')
- backend_env = os.environ.get('QUTE_BDD_BACKEND')
- config.webengine = (backend_arg == 'webengine' or
- backend_env == 'webengine' or
- config.backend == 'webengine')
-
- earlyinit.configure_pyqt()
+ return 'webengine'
def pytest_report_header(config):