tests: Add a reason argument to platform markers.

This commit is contained in:
Florian Bruhin 2015-10-02 08:46:28 +02:00
parent b42b12b7a5
commit 9f7836131d
2 changed files with 28 additions and 18 deletions

View File

@ -84,18 +84,28 @@ def pytest_runtest_setup(item):
if not isinstance(item, item.Function): if not isinstance(item, item.Function):
return return
if item.get_marker('posix') and os.name != 'posix': markers = [
pytest.skip("Requires a POSIX os.") ('posix', os.name != 'posix', "Requires a POSIX os"),
elif item.get_marker('windows') and os.name != 'nt': ('windows', os.name != 'nt', "Requires Windows"),
pytest.skip("Requires Windows.") ('linux', not sys.platform.startswith('linux'), "Requires Linux"),
elif item.get_marker('linux') and not sys.platform.startswith('linux'): ('osx', sys.platform != 'darwin', "Requires OS X"),
pytest.skip("Requires Linux.") ('not_frozen', getattr(sys, 'frozen', False),
elif item.get_marker('osx') and sys.platform != 'darwin': "Can't be run when frozen"),
pytest.skip("Requires OS X.") ('frozen', not getattr(sys, 'frozen', False),
elif item.get_marker('not_frozen') and getattr(sys, 'frozen', False): "Can only run when frozen"),
pytest.skip("Can't be run when frozen!") ]
elif item.get_marker('frozen') and not getattr(sys, 'frozen', False):
pytest.skip("Can only run when frozen!") for searched_marker, condition, default_reason in markers:
marker = item.get_marker(searched_marker)
if marker and condition:
assert not marker.args
assert set(marker.kwargs).issubset({'reason'})
if 'reason' in marker.kwargs:
reason = '{}: {}'.format(default_reason,
marker.kwargs['reason'])
else:
reason = default_reason + '.'
pytest.skip(reason)
@pytest.fixture(scope='session') @pytest.fixture(scope='session')

View File

@ -538,7 +538,7 @@ class TestSendToRunningInstance:
assert msg == "No existing instance present (error 2)" assert msg == "No existing instance present (error 2)"
@pytest.mark.parametrize('has_cwd', [True, False]) @pytest.mark.parametrize('has_cwd', [True, False])
@pytest.mark.posix # Causes random trouble on Windows @pytest.mark.posix(reason="Causes random trouble on Windows")
def test_normal(self, qtbot, tmpdir, ipc_server, mocker, has_cwd): def test_normal(self, qtbot, tmpdir, ipc_server, mocker, has_cwd):
ipc_server.listen() ipc_server.listen()
spy = QSignalSpy(ipc_server.got_args) spy = QSignalSpy(ipc_server.got_args)
@ -665,7 +665,7 @@ class TestSendOrListen:
yield legacy_server yield legacy_server
legacy_server.shutdown() legacy_server.shutdown()
@pytest.mark.posix # Flaky on Windows @pytest.mark.posix(reason="Flaky on Windows")
def test_normal_connection(self, caplog, qtbot, args): def test_normal_connection(self, caplog, qtbot, args):
ret_server = ipc.send_or_listen(args) ret_server = ipc.send_or_listen(args)
assert isinstance(ret_server, ipc.IPCServer) assert isinstance(ret_server, ipc.IPCServer)
@ -679,7 +679,7 @@ class TestSendOrListen:
assert ret_client is None assert ret_client is None
@pytest.mark.posix # Unneeded on Windows @pytest.mark.posix(reason="Unneeded on Windows")
def test_legacy_name(self, caplog, qtbot, args, legacy_server): def test_legacy_name(self, caplog, qtbot, args, legacy_server):
with qtbot.waitSignal(legacy_server.got_args, raising=True): with qtbot.waitSignal(legacy_server.got_args, raising=True):
ret = ipc.send_or_listen(args) ret = ipc.send_or_listen(args)
@ -687,7 +687,7 @@ class TestSendOrListen:
msgs = [e.message for e in caplog.records()] msgs = [e.message for e in caplog.records()]
assert "Connecting to {}".format(legacy_server._socketname) in msgs assert "Connecting to {}".format(legacy_server._socketname) in msgs
@pytest.mark.posix # Unneeded on Windows @pytest.mark.posix(reason="Unneeded on Windows")
@pytest.mark.not_frozen @pytest.mark.not_frozen
def test_stale_legacy_server(self, caplog, qtbot, args, legacy_server, def test_stale_legacy_server(self, caplog, qtbot, args, legacy_server,
ipc_server, py_proc): ipc_server, py_proc):
@ -728,7 +728,7 @@ class TestSendOrListen:
assert ret_client is None assert ret_client is None
@pytest.mark.posix # Unneeded on Windows @pytest.mark.posix(reason="Unneeded on Windows")
def test_correct_socket_name(self, args): def test_correct_socket_name(self, args):
server = ipc.send_or_listen(args) server = ipc.send_or_listen(args)
expected_dir = ipc._get_socketname(args.basedir) expected_dir = ipc._get_socketname(args.basedir)
@ -816,7 +816,7 @@ class TestSendOrListen:
] ]
assert records[0].msg == '\n'.join(error_msgs) assert records[0].msg == '\n'.join(error_msgs)
@pytest.mark.posix # Flaky on Windows @pytest.mark.posix("Flaky on Windows")
def test_error_while_listening(self, qlocalserver_mock, caplog, args): def test_error_while_listening(self, qlocalserver_mock, caplog, args):
"""Test an error with the first listen call.""" """Test an error with the first listen call."""
qlocalserver_mock().listen.return_value = False qlocalserver_mock().listen.return_value = False