summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2017-12-19 08:29:39 +0100
committerFlorian Bruhin <git@the-compiler.org>2017-12-19 08:32:32 +0100
commit12ba64254746fc7dd55925f2f3b79844b719eea4 (patch)
tree43388733996f772e46bd99499f46ed510cdfd05f
parentdbb89b1073db8a7a7da6b0e7cb5fae504580febf (diff)
downloadqutebrowser-12ba64254746fc7dd55925f2f3b79844b719eea4.tar.gz
qutebrowser-12ba64254746fc7dd55925f2f3b79844b719eea4.zip
Avoid using pytest.config
It's going to be removed in some future pytest release.
-rw-r--r--tests/end2end/fixtures/quteprocess.py14
-rw-r--r--tests/end2end/fixtures/test_quteprocess.py13
-rw-r--r--tests/end2end/fixtures/test_testprocess.py16
-rw-r--r--tests/end2end/fixtures/testprocess.py24
-rw-r--r--tests/end2end/fixtures/webserver.py10
5 files changed, 42 insertions, 35 deletions
diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py
index 3f5e727e6..8c9acd6ce 100644
--- a/tests/end2end/fixtures/quteprocess.py
+++ b/tests/end2end/fixtures/quteprocess.py
@@ -44,9 +44,9 @@ from end2end.fixtures import testprocess
instance_counter = itertools.count()
-def is_ignored_qt_message(message):
+def is_ignored_qt_message(pytestconfig, message):
"""Check if the message is listed in qt_log_ignore."""
- regexes = pytest.config.getini('qt_log_ignore')
+ regexes = pytestconfig.getini('qt_log_ignore')
for regex in regexes:
if re.search(regex, message):
return True
@@ -207,7 +207,7 @@ class LogLine(testprocess.Line):
expected: Whether the message was expected or not.
"""
- def __init__(self, data):
+ def __init__(self, pytestconfig, data):
super().__init__(data)
try:
line = json.loads(data)
@@ -229,7 +229,7 @@ class LogLine(testprocess.Line):
self.traceback = line.get('traceback')
self.message = line['message']
- self.expected = is_ignored_qt_message(self.message)
+ self.expected = is_ignored_qt_message(pytestconfig, self.message)
self.use_color = False
def __str__(self):
@@ -299,7 +299,7 @@ class QuteProc(testprocess.Process):
'message']
def __init__(self, request, *, parent=None):
- super().__init__(parent)
+ super().__init__(request.config, parent)
self._ipc_socket = None
self.basedir = None
self._focus_ready = False
@@ -372,11 +372,11 @@ class QuteProc(testprocess.Process):
def _parse_line(self, line):
try:
- log_line = LogLine(line)
+ log_line = LogLine(self._pytestconfig, line)
except testprocess.InvalidLine:
if not line.strip():
return None
- elif (is_ignored_qt_message(line) or
+ elif (is_ignored_qt_message(self._pytestconfig, line) or
is_ignored_lowlevel_message(line) or
is_ignored_chromium_message(line) or
self.request.node.get_marker('no_invalid_lines')):
diff --git a/tests/end2end/fixtures/test_quteprocess.py b/tests/end2end/fixtures/test_quteprocess.py
index f8241397f..528d29948 100644
--- a/tests/end2end/fixtures/test_quteprocess.py
+++ b/tests/end2end/fixtures/test_quteprocess.py
@@ -222,8 +222,8 @@ def test_quteprocess_quitting(qtbot, quteproc_process):
{'category': 'py.warnings'},
id='resourcewarning'),
])
-def test_log_line_parse(data, attrs):
- line = quteprocess.LogLine(data)
+def test_log_line_parse(pytestconfig, data, attrs):
+ line = quteprocess.LogLine(pytestconfig, data)
for name, expected in attrs.items():
actual = getattr(line, name)
assert actual == expected, name
@@ -283,9 +283,10 @@ def test_log_line_parse(data, attrs):
'\033[36mfoo bar:qux:10\033[0m \033[37mquux\033[0m',
id='expected error colorized'),
])
-def test_log_line_formatted(data, colorized, expect_error, expected):
+def test_log_line_formatted(pytestconfig,
+ data, colorized, expect_error, expected):
line = json.dumps(data)
- record = quteprocess.LogLine(line)
+ record = quteprocess.LogLine(pytestconfig, line)
record.expected = expect_error
ts = datetime.datetime.fromtimestamp(data['created']).strftime('%H:%M:%S')
ts += '.{:03.0f}'.format(data['msecs'])
@@ -293,9 +294,9 @@ def test_log_line_formatted(data, colorized, expect_error, expected):
assert record.formatted_str(colorized=colorized) == expected
-def test_log_line_no_match():
+def test_log_line_no_match(pytestconfig):
with pytest.raises(testprocess.InvalidLine):
- quteprocess.LogLine("Hello World!")
+ quteprocess.LogLine(pytestconfig, "Hello World!")
class TestClickElementByText:
diff --git a/tests/end2end/fixtures/test_testprocess.py b/tests/end2end/fixtures/test_testprocess.py
index 1811b7fb1..733191415 100644
--- a/tests/end2end/fixtures/test_testprocess.py
+++ b/tests/end2end/fixtures/test_testprocess.py
@@ -51,8 +51,8 @@ class PythonProcess(testprocess.Process):
"""A testprocess which runs the given Python code."""
- def __init__(self):
- super().__init__()
+ def __init__(self, pytestconfig):
+ super().__init__(pytestconfig)
self.proc.setReadChannel(QProcess.StandardOutput)
self.code = None
@@ -103,22 +103,22 @@ class NoReadyPythonProcess(PythonProcess):
@pytest.fixture
-def pyproc():
- proc = PythonProcess()
+def pyproc(pytestconfig):
+ proc = PythonProcess(pytestconfig)
yield proc
proc.terminate()
@pytest.fixture
-def quit_pyproc():
- proc = QuitPythonProcess()
+def quit_pyproc(pytestconfig):
+ proc = QuitPythonProcess(pytestconfig)
yield proc
proc.terminate()
@pytest.fixture
-def noready_pyproc():
- proc = NoReadyPythonProcess()
+def noready_pyproc(pytestconfig):
+ proc = NoReadyPythonProcess(pytestconfig)
yield proc
proc.terminate()
diff --git a/tests/end2end/fixtures/testprocess.py b/tests/end2end/fixtures/testprocess.py
index ac220af58..e504bcc1b 100644
--- a/tests/end2end/fixtures/testprocess.py
+++ b/tests/end2end/fixtures/testprocess.py
@@ -73,12 +73,11 @@ class Line:
waited_for = attr.ib(False)
-def _render_log(data, threshold=100):
+def _render_log(data, *, verbose, threshold=100):
"""Shorten the given log without -v and convert to a string."""
data = [str(d) for d in data]
is_exception = any('Traceback (most recent call last):' in line or
'Uncaught exception' in line for line in data)
- verbose = pytest.config.getoption('--verbose')
if len(data) > threshold and not verbose and not is_exception:
msg = '[{} lines suppressed, use -v to show]'.format(
len(data) - threshold)
@@ -105,15 +104,17 @@ def pytest_runtest_makereport(item, call):
# is actually a tuple. This is handled similarily in pytest-qt too.
return
- if pytest.config.getoption('--capture') == 'no':
+ if item.config.getoption('--capture') == 'no':
# Already printed live
return
+ verbose = item.config.getoption('--verbose')
if quteproc_log is not None:
report.longrepr.addsection("qutebrowser output",
- _render_log(quteproc_log))
+ _render_log(quteproc_log, verbose=verbose))
if server_log is not None:
- report.longrepr.addsection("server output", _render_log(server_log))
+ report.longrepr.addsection("server output",
+ _render_log(server_log, verbose=verbose))
class Process(QObject):
@@ -128,6 +129,7 @@ class Process(QObject):
_started: Whether the process was ever started.
proc: The QProcess for the underlying process.
exit_expected: Whether the process is expected to quit.
+ pytestconfig: The pytestconfig fixture.
Signals:
ready: Emitted when the server finished starting up.
@@ -138,8 +140,9 @@ class Process(QObject):
new_data = pyqtSignal(object)
KEYS = ['data']
- def __init__(self, parent=None):
+ def __init__(self, pytestconfig, parent=None):
super().__init__(parent)
+ self._pytestconfig = pytestconfig
self.captured_log = []
self._started = False
self._invalid = []
@@ -150,7 +153,7 @@ class Process(QObject):
def _log(self, line):
"""Add the given line to the captured log output."""
- if pytest.config.getoption('--capture') == 'no':
+ if self._pytestconfig.getoption('--capture') == 'no':
print(line)
self.captured_log.append(line)
@@ -225,6 +228,8 @@ class Process(QObject):
"""Start the process and wait until it started."""
self._start(args, env=env)
self._started = True
+ verbose = self._pytestconfig.getoption('--verbose')
+
timeout = 60 if 'CI' in os.environ else 20
for _ in range(timeout):
with self._wait_signal(self.ready, timeout=1000,
@@ -236,14 +241,15 @@ class Process(QObject):
return
# _start ensures it actually started, but it might quit shortly
# afterwards
- raise ProcessExited('\n' + _render_log(self.captured_log))
+ raise ProcessExited('\n' + _render_log(self.captured_log,
+ verbose=verbose))
if blocker.signal_triggered:
self._after_start()
return
raise WaitForTimeout("Timed out while waiting for process start.\n" +
- _render_log(self.captured_log))
+ _render_log(self.captured_log, verbose=verbose))
def _start(self, args, env):
"""Actually start the process."""
diff --git a/tests/end2end/fixtures/webserver.py b/tests/end2end/fixtures/webserver.py
index a40c62015..b86a55b35 100644
--- a/tests/end2end/fixtures/webserver.py
+++ b/tests/end2end/fixtures/webserver.py
@@ -137,8 +137,8 @@ class WebserverProcess(testprocess.Process):
KEYS = ['verb', 'path']
- def __init__(self, script, parent=None):
- super().__init__(parent)
+ def __init__(self, pytestconfig, script, parent=None):
+ super().__init__(pytestconfig, parent)
self._script = script
self.port = utils.random_port()
self.new_data.connect(self.new_request)
@@ -174,9 +174,9 @@ class WebserverProcess(testprocess.Process):
@pytest.fixture(scope='session', autouse=True)
-def server(qapp):
+def server(qapp, pytestconfig):
"""Fixture for an server object which ensures clean setup/teardown."""
- server = WebserverProcess('webserver_sub')
+ server = WebserverProcess(pytestconfig, 'webserver_sub')
server.start()
yield server
server.terminate()
@@ -198,7 +198,7 @@ def ssl_server(request, qapp):
This needs to be explicitly used in a test, and overwrites the server log
used in that test.
"""
- server = WebserverProcess('webserver_sub_ssl')
+ server = WebserverProcess(request.config, 'webserver_sub_ssl')
request.node._server_log = server.captured_log
server.start()
yield server