Skip GUI tests when no DISPLAY is available.

Fixes #851.
This commit is contained in:
Florian Bruhin 2015-08-09 20:47:50 +02:00
parent fbf53168c2
commit 2fe1bcfc2b
6 changed files with 20 additions and 13 deletions

View File

@ -238,6 +238,7 @@ class TestDefaultConfig:
"""Test validating of the default config.""" """Test validating of the default config."""
@pytest.mark.usefixtures('qapp')
def test_default_config(self): def test_default_config(self):
"""Test validating of the default config.""" """Test validating of the default config."""
conf = config.ConfigManager(None, None) conf = config.ConfigManager(None, None)

View File

@ -120,8 +120,14 @@ def pytest_collection_modifyitems(items):
http://pytest.org/latest/plugins.html http://pytest.org/latest/plugins.html
""" """
for item in items: for item in items:
if 'qtbot' in getattr(item, 'fixturenames', ()): if 'qapp' in getattr(item, 'fixturenames', ()):
item.add_marker('gui') 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(): def _generate_cmdline_tests():

View File

@ -185,7 +185,7 @@ class TestKeyChain:
self.kp.execute.assert_called_once_with('0', self.kp.Type.chain, None) self.kp.execute.assert_called_once_with('0', self.kp.Type.chain, None)
assert self.kp._keystring == '' 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): monkeypatch):
"""Test ambiguous keychain.""" """Test ambiguous keychain."""
config_stub.data = CONFIG config_stub.data = CONFIG

View File

@ -505,19 +505,18 @@ class TestSavefileOpen:
@pytest.mark.parametrize('orgname, expected', [(None, ''), ('test', 'test')]) @pytest.mark.parametrize('orgname, expected', [(None, ''), ('test', 'test')])
def test_unset_organization(orgname, expected): def test_unset_organization(qapp, orgname, expected):
"""Test unset_organization. """Test unset_organization.
Args: Args:
orgname: The organizationName to set initially. orgname: The organizationName to set initially.
expected: The organizationName which is expected when reading back. expected: The organizationName which is expected when reading back.
""" """
app = QApplication.instance() qapp.setOrganizationName(orgname)
app.setOrganizationName(orgname) assert qapp.organizationName() == expected # sanity check
assert app.organizationName() == expected # sanity check
with qtutils.unset_organization(): with qtutils.unset_organization():
assert app.organizationName() == '' assert qapp.organizationName() == ''
assert app.organizationName() == expected assert qapp.organizationName() == expected
if test_file is not None: if test_file is not None:
@ -921,6 +920,7 @@ class TestPyQIODevice:
assert str(excinfo.value) == 'Reading failed' assert str(excinfo.value) == 'Reading failed'
@pytest.mark.usefixtures('qapp')
class TestEventLoop: class TestEventLoop:
"""Tests for EventLoop. """Tests for EventLoop.

View File

@ -36,16 +36,16 @@ from qutebrowser.utils import standarddir
@pytest.yield_fixture(autouse=True) @pytest.yield_fixture(autouse=True)
def change_qapp_name(): def change_qapp_name(qapp):
"""Change the name of the QApplication instance. """Change the name of the QApplication instance.
This changes the applicationName for all tests in this module to This changes the applicationName for all tests in this module to
"qutebrowser_test". "qutebrowser_test".
""" """
old_name = QApplication.instance().applicationName() old_name = qapp.applicationName()
QApplication.instance().setApplicationName('qutebrowser_test') qapp.setApplicationName('qutebrowser_test')
yield yield
QApplication.instance().setApplicationName(old_name) qapp.setApplicationName(old_name)
@pytest.fixture @pytest.fixture

View File

@ -11,7 +11,7 @@ envlist = py34,misc,pep257,pyflakes,pep8,mccabe,pylint,pyroma,check-manifest
setenv = setenv =
QT_QPA_PLATFORM_PLUGIN_PATH={envdir}/Lib/site-packages/PyQt5/plugins/platforms QT_QPA_PLATFORM_PLUGIN_PATH={envdir}/Lib/site-packages/PyQt5/plugins/platforms
PYTEST_QT_API=pyqt5 PYTEST_QT_API=pyqt5
passenv = PYTHON DISPLAY XAUTHORITY HOME USERNAME USER passenv = PYTHON DISPLAY XAUTHORITY HOME USERNAME USER CI
deps = deps =
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
py==1.4.30 py==1.4.30