diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 3fff0ea66..76ef7f7ff 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -238,6 +238,7 @@ class TestDefaultConfig: """Test validating of the default config.""" + @pytest.mark.usefixtures('qapp') def test_default_config(self): """Test validating of the default config.""" conf = config.ConfigManager(None, None) diff --git a/tests/conftest.py b/tests/conftest.py index 6c22a2cd9..d88437225 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -120,8 +120,14 @@ def pytest_collection_modifyitems(items): http://pytest.org/latest/plugins.html """ for item in items: - if 'qtbot' in getattr(item, 'fixturenames', ()): + if 'qapp' in getattr(item, 'fixturenames', ()): item.add_marker('gui') + if sys.platform == 'linux' and not os.environ.get('DISPLAY', ''): + if 'CI' in os.environ: + raise Exception("No display available on CI!") + skip_marker = pytest.mark.skipif( + True, reason="No DISPLAY available") + item.add_marker(skip_marker) def _generate_cmdline_tests(): diff --git a/tests/keyinput/test_basekeyparser.py b/tests/keyinput/test_basekeyparser.py index d068e040e..cb3f693f5 100644 --- a/tests/keyinput/test_basekeyparser.py +++ b/tests/keyinput/test_basekeyparser.py @@ -185,7 +185,7 @@ class TestKeyChain: self.kp.execute.assert_called_once_with('0', self.kp.Type.chain, None) assert self.kp._keystring == '' - def test_ambiguous_keychain(self, fake_keyevent_factory, config_stub, + def test_ambiguous_keychain(self, qapp, fake_keyevent_factory, config_stub, monkeypatch): """Test ambiguous keychain.""" config_stub.data = CONFIG diff --git a/tests/utils/test_qtutils.py b/tests/utils/test_qtutils.py index 0f1b9b768..a28654b0d 100644 --- a/tests/utils/test_qtutils.py +++ b/tests/utils/test_qtutils.py @@ -505,19 +505,18 @@ class TestSavefileOpen: @pytest.mark.parametrize('orgname, expected', [(None, ''), ('test', 'test')]) -def test_unset_organization(orgname, expected): +def test_unset_organization(qapp, orgname, expected): """Test unset_organization. Args: orgname: The organizationName to set initially. expected: The organizationName which is expected when reading back. """ - app = QApplication.instance() - app.setOrganizationName(orgname) - assert app.organizationName() == expected # sanity check + qapp.setOrganizationName(orgname) + assert qapp.organizationName() == expected # sanity check with qtutils.unset_organization(): - assert app.organizationName() == '' - assert app.organizationName() == expected + assert qapp.organizationName() == '' + assert qapp.organizationName() == expected if test_file is not None: @@ -921,6 +920,7 @@ class TestPyQIODevice: assert str(excinfo.value) == 'Reading failed' +@pytest.mark.usefixtures('qapp') class TestEventLoop: """Tests for EventLoop. diff --git a/tests/utils/test_standarddir.py b/tests/utils/test_standarddir.py index 704c57c0f..6e79ab21a 100644 --- a/tests/utils/test_standarddir.py +++ b/tests/utils/test_standarddir.py @@ -36,16 +36,16 @@ from qutebrowser.utils import standarddir @pytest.yield_fixture(autouse=True) -def change_qapp_name(): +def change_qapp_name(qapp): """Change the name of the QApplication instance. This changes the applicationName for all tests in this module to "qutebrowser_test". """ - old_name = QApplication.instance().applicationName() - QApplication.instance().setApplicationName('qutebrowser_test') + old_name = qapp.applicationName() + qapp.setApplicationName('qutebrowser_test') yield - QApplication.instance().setApplicationName(old_name) + qapp.setApplicationName(old_name) @pytest.fixture diff --git a/tox.ini b/tox.ini index f992f30b1..a488d2761 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ envlist = py34,misc,pep257,pyflakes,pep8,mccabe,pylint,pyroma,check-manifest setenv = QT_QPA_PLATFORM_PLUGIN_PATH={envdir}/Lib/site-packages/PyQt5/plugins/platforms PYTEST_QT_API=pyqt5 -passenv = PYTHON DISPLAY XAUTHORITY HOME USERNAME USER +passenv = PYTHON DISPLAY XAUTHORITY HOME USERNAME USER CI deps = -r{toxinidir}/requirements.txt py==1.4.30