Use request instead of pytestconfig

This unifies QuteProc and the other Process subclasses a bit.
This commit is contained in:
Florian Bruhin 2017-12-19 08:35:00 +01:00
parent 12ba642547
commit f2c93a0061
5 changed files with 30 additions and 24 deletions

View File

@ -299,14 +299,13 @@ class QuteProc(testprocess.Process):
'message']
def __init__(self, request, *, parent=None):
super().__init__(request.config, parent)
super().__init__(request, parent)
self._ipc_socket = None
self.basedir = None
self._focus_ready = False
self._load_ready = False
self._instance_id = next(instance_counter)
self._run_counter = itertools.count()
self.request = request
def _is_ready(self, what):
"""Called by _parse_line if loading/focusing is done.
@ -372,11 +371,11 @@ class QuteProc(testprocess.Process):
def _parse_line(self, line):
try:
log_line = LogLine(self._pytestconfig, line)
log_line = LogLine(self.request.config, line)
except testprocess.InvalidLine:
if not line.strip():
return None
elif (is_ignored_qt_message(self._pytestconfig, line) or
elif (is_ignored_qt_message(self.request.config, line) or
is_ignored_lowlevel_message(line) or
is_ignored_chromium_message(line) or
self.request.node.get_marker('no_invalid_lines')):

View File

@ -45,6 +45,10 @@ class FakeConfig:
'--qute-delay': 0,
'--color': True,
'--verbose': False,
'--capture': None,
}
INI = {
'qt_log_ignore': [],
}
def __init__(self):
@ -53,6 +57,9 @@ class FakeConfig:
def getoption(self, name):
return self.ARGS[name]
def getini(self, name):
return self.INI[name]
class FakeNode:

View File

@ -51,8 +51,8 @@ class PythonProcess(testprocess.Process):
"""A testprocess which runs the given Python code."""
def __init__(self, pytestconfig):
super().__init__(pytestconfig)
def __init__(self, request):
super().__init__(request)
self.proc.setReadChannel(QProcess.StandardOutput)
self.code = None
@ -103,22 +103,22 @@ class NoReadyPythonProcess(PythonProcess):
@pytest.fixture
def pyproc(pytestconfig):
proc = PythonProcess(pytestconfig)
def pyproc(request):
proc = PythonProcess(request)
yield proc
proc.terminate()
@pytest.fixture
def quit_pyproc(pytestconfig):
proc = QuitPythonProcess(pytestconfig)
def quit_pyproc(request):
proc = QuitPythonProcess(request)
yield proc
proc.terminate()
@pytest.fixture
def noready_pyproc(pytestconfig):
proc = NoReadyPythonProcess(pytestconfig)
def noready_pyproc(request):
proc = NoReadyPythonProcess(request)
yield proc
proc.terminate()
@ -149,9 +149,9 @@ def test_process_never_started(qtbot, quit_pyproc):
quit_pyproc.after_test()
def test_wait_signal_raising(qtbot):
def test_wait_signal_raising(request, qtbot):
"""testprocess._wait_signal should raise by default."""
proc = testprocess.Process()
proc = testprocess.Process(request)
with pytest.raises(qtbot.TimeoutError):
with proc._wait_signal(proc.proc.started, timeout=0):
pass

View File

@ -129,7 +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.
request: The request object for the current test.
Signals:
ready: Emitted when the server finished starting up.
@ -140,9 +140,9 @@ class Process(QObject):
new_data = pyqtSignal(object)
KEYS = ['data']
def __init__(self, pytestconfig, parent=None):
def __init__(self, request, parent=None):
super().__init__(parent)
self._pytestconfig = pytestconfig
self.request = request
self.captured_log = []
self._started = False
self._invalid = []
@ -153,7 +153,7 @@ class Process(QObject):
def _log(self, line):
"""Add the given line to the captured log output."""
if self._pytestconfig.getoption('--capture') == 'no':
if self.request.config.getoption('--capture') == 'no':
print(line)
self.captured_log.append(line)
@ -228,7 +228,7 @@ class Process(QObject):
"""Start the process and wait until it started."""
self._start(args, env=env)
self._started = True
verbose = self._pytestconfig.getoption('--verbose')
verbose = self.request.config.getoption('--verbose')
timeout = 60 if 'CI' in os.environ else 20
for _ in range(timeout):

View File

@ -137,8 +137,8 @@ class WebserverProcess(testprocess.Process):
KEYS = ['verb', 'path']
def __init__(self, pytestconfig, script, parent=None):
super().__init__(pytestconfig, parent)
def __init__(self, request, script, parent=None):
super().__init__(request, 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, pytestconfig):
def server(qapp, request):
"""Fixture for an server object which ensures clean setup/teardown."""
server = WebserverProcess(pytestconfig, 'webserver_sub')
server = WebserverProcess(request, '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(request.config, 'webserver_sub_ssl')
server = WebserverProcess(request, 'webserver_sub_ssl')
request.node._server_log = server.captured_log
server.start()
yield server