diff --git a/tests/conftest.py b/tests/conftest.py index e99086635..f7164e1b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,6 +36,8 @@ from helpers.messagemock import message_mock from qutebrowser.config import config from qutebrowser.utils import objreg +from PyQt5.QtNetwork import QNetworkCookieJar + def pytest_collection_modifyitems(items): """Automatically add a 'gui' marker to all gui-related tests. @@ -269,3 +271,15 @@ def fake_keyevent_factory(): return evtmock return fake_keyevent + + +@pytest.yield_fixture +def cookiejar_and_cache(stubs): + """Fixture providing a fake cookie jar and cache.""" + jar = QNetworkCookieJar() + cache = stubs.FakeNetworkCache() + objreg.register('cookie-jar', jar) + objreg.register('cache', cache) + yield + objreg.delete('cookie-jar') + objreg.delete('cache') diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index fad28abe4..88884cf73 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -24,12 +24,37 @@ from unittest import mock from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject -from PyQt5.QtNetwork import QNetworkRequest +from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache, + QNetworkCacheMetaData) from PyQt5.QtWidgets import QCommonStyle from qutebrowser.config import configexc +class FakeNetworkCache(QAbstractNetworkCache): + + def cacheSize(self): + return 0 + + def data(self, _url): + return None + + def insert(self, _dev): + pass + + def metaData(self, _url): + return QNetworkCacheMetaData() + + def prepare(self, _metadata): + return None + + def remove(self, _url): + return False + + def updateMetaData(self, _url): + pass + + class FakeKeyEvent: """Fake QKeyPressEvent stub.""" diff --git a/tests/unit/browser/test_commands.py b/tests/unit/browser/test_commands.py index 4343175e7..c570ad1b4 100644 --- a/tests/unit/browser/test_commands.py +++ b/tests/unit/browser/test_commands.py @@ -33,28 +33,7 @@ from qutebrowser.keyinput import modeman ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd']) -class FakeNetworkCache(QAbstractNetworkCache): - - def cacheSize(self): - return 0 - - def data(self, _url): - return None - - def insert(self, _dev): - pass - - def metaData(self, _url): - return QNetworkCacheMetaData() - - def prepare(self, _metadata): - return None - - def remove(self, _url): - return False - - def updateMetaData(self, _url): - pass +pytestmark = pytest.mark.usefixtures('cookiejar_and_cache') @pytest.yield_fixture(autouse=True)