From 2eae6a06030f72a224bad1fe258f9f0f28edae3e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 19 Aug 2016 13:11:29 +0200 Subject: [PATCH] bdd: Wait less for xfailing tests We now divide all timeouts by ten for xfailing tests, with the hope to still catch newly passing tests, but not spend too much time waiting. With a quick test, this reduced the testsuite run length from 12 to 7-8 minutes. --- tests/end2end/fixtures/quteprocess.py | 9 +++++++++ tests/end2end/fixtures/test_quteprocess.py | 13 +++++++++++-- tests/end2end/fixtures/testprocess.py | 6 +++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py index df2818888..7a6e83413 100644 --- a/tests/end2end/fixtures/quteprocess.py +++ b/tests/end2end/fixtures/quteprocess.py @@ -293,6 +293,15 @@ class QuteProc(testprocess.Process): function='javaScriptConsoleMessage', message='[*] {}'.format(message)) + def wait_for(self, timeout=None, **kwargs): + """Extend wait_for to add divisor if a test is xfailing.""" + xfail = self.request.node.get_marker('xfail') + if xfail and xfail.args[0]: + kwargs['divisor'] = 10 + else: + kwargs['divisor'] = 1 + return super().wait_for(timeout=timeout, **kwargs) + def _is_error_logline(self, msg): """Check if the given LogLine is some kind of error message.""" is_js_error = (msg.category == 'js' and diff --git a/tests/end2end/fixtures/test_quteprocess.py b/tests/end2end/fixtures/test_quteprocess.py index d2d7a5f41..84c88f3d6 100644 --- a/tests/end2end/fixtures/test_quteprocess.py +++ b/tests/end2end/fixtures/test_quteprocess.py @@ -22,7 +22,6 @@ import logging import datetime import json -import collections import pytest @@ -50,6 +49,16 @@ class FakeConfig: def getoption(self, name): return self.ARGS[name] +class FakeNode: + + """Fake for request.node""" + + def __init__(self, call): + self.rep_call = call + + def get_marker(self, _name): + return None + class FakeRequest: @@ -70,7 +79,7 @@ def request_mock(quteproc, monkeypatch, httpbin): """Patch out a pytest request.""" fake_call = FakeRepCall() fake_config = FakeConfig() - fake_node = collections.namedtuple('FakeNode', ['rep_call'])(fake_call) + fake_node = FakeNode(fake_call) fake_request = FakeRequest(fake_node, fake_config, httpbin) assert not hasattr(fake_request.node.rep_call, 'wasxfail') monkeypatch.setattr(quteproc, 'request', fake_request) diff --git a/tests/end2end/fixtures/testprocess.py b/tests/end2end/fixtures/testprocess.py index 1b624ce29..cb45671ad 100644 --- a/tests/end2end/fixtures/testprocess.py +++ b/tests/end2end/fixtures/testprocess.py @@ -424,7 +424,7 @@ class Process(QObject): pass def wait_for(self, timeout=None, *, override_waited_for=False, - do_skip=False, **kwargs): + do_skip=False, divisor=1, **kwargs): """Wait until a given value is found in the data. Keyword arguments to this function get interpreted as attributes of the @@ -436,6 +436,7 @@ class Process(QObject): override_waited_for: If set, gets triggered by previous messages again. do_skip: If set, call pytest.skip on a timeout. + divisor: A factor to decrease the timeout by. Return: The matched line. @@ -449,6 +450,9 @@ class Process(QObject): timeout = 15000 else: timeout = 5000 + + timeout /= divisor + if not kwargs: raise TypeError("No keyword arguments given!") for key in kwargs: