Prevent test_tab from creating user data dir.
This is another case (like test_qt_javascript) that needs redirection of XDG_DATA_HOME to prevent Qt from creating ~/.share/local/qute_test.
This commit is contained in:
parent
5ae9d985b1
commit
7d36847f77
@ -432,3 +432,14 @@ def data_tmpdir(monkeypatch, tmpdir):
|
||||
os.mkdir(path)
|
||||
monkeypatch.setattr('qutebrowser.utils.standarddir.data', lambda: path)
|
||||
return tmpdir
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def redirect_xdg_data(data_tmpdir):
|
||||
"""Set XDG_DATA_HOME to a temp location.
|
||||
|
||||
While data_tmpdir covers most cases by redirecting standarddir.data(), this
|
||||
is not enough for places Qt references the data dir internally. For these,
|
||||
we need to set the environment variable to redirect data access.
|
||||
"""
|
||||
os.putenv('XDG_DATA_HOME', str(data_tmpdir))
|
||||
|
@ -25,6 +25,8 @@ from qutebrowser.browser import browsertab
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.utils import objreg
|
||||
|
||||
pytestmark = pytest.mark.usefixtures('redirect_xdg_data')
|
||||
|
||||
try:
|
||||
from PyQt5.QtWebKitWidgets import QWebView
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from PyQt5.QtCore import QObject, pyqtSignal
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
@ -65,18 +64,14 @@ def test_element_js_webkit(webview, js_enabled, expected):
|
||||
assert result == expected
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('redirect_xdg_data')
|
||||
@pytest.mark.parametrize('js_enabled, expected', [(True, 2.0), (False, 2.0)])
|
||||
def test_simple_js_webengine(qtbot, webengineview, js_enabled, expected,
|
||||
data_tmpdir):
|
||||
def test_simple_js_webengine(qtbot, webengineview, js_enabled, expected):
|
||||
"""With QtWebEngine, runJavaScript works even when JS is off."""
|
||||
# pylint: disable=no-name-in-module,useless-suppression
|
||||
# If we get there (because of the webengineview fixture) we can be certain
|
||||
# QtWebEngine is available
|
||||
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
|
||||
# runJavaScript will write to the data directory. As the path is determined
|
||||
# by Qt and bypasses standarddir.data(), the data_tmpdir fixture is not
|
||||
# enough -- we need to set XDG_DATA_HOME as well
|
||||
os.putenv('XDG_DATA_HOME', str(data_tmpdir))
|
||||
webengineview.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
|
||||
js_enabled)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user