From 021ea444a16ead0681605960c0821400f411acb9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 9 Nov 2015 07:43:48 +0100 Subject: [PATCH] bdd: Fix separations between tests. With this change, no test should affect another one anymore. Changes in detail: - Before each test, invalid lines are cleaned so the invalid output from the previous test doesn't affect the next one. - Before each test, qutebrowser is restarted if it was quit. - After each test, the data is cleared properly in every case. - If there was an invalid output, the test waits for 1s for more output, and then terminates qutebrowser so it's restarted with a clean state. --- tests/integration/quteprocess.py | 1 + tests/integration/testprocess.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/integration/quteprocess.py b/tests/integration/quteprocess.py index 1fe0e4782..ab3726d61 100644 --- a/tests/integration/quteprocess.py +++ b/tests/integration/quteprocess.py @@ -240,5 +240,6 @@ def quteproc(qapp, httpbin): @pytest.yield_fixture(autouse=True) def quteproc_after_test(quteproc): """Fixture to run cleanup tasks after each test.""" + quteproc.before_test() yield quteproc.after_test() diff --git a/tests/integration/testprocess.py b/tests/integration/testprocess.py index cf774456f..4b7608464 100644 --- a/tests/integration/testprocess.py +++ b/tests/integration/testprocess.py @@ -20,6 +20,7 @@ """Base class for a subprocess run for tests..""" import re +import time import fnmatch import pytestqt.plugin # pylint: disable=import-error @@ -153,15 +154,27 @@ class Process(QObject): assert ok assert self.is_running() + def before_test(self): + """Restart process before a test if it exited before.""" + self._invalid = [] + if not self.is_running(): + self.start() + def after_test(self): """Clean up data after each test. Also checks self._invalid so the test counts as failed if there were unexpected output lines earlier. """ - self._data.clear() if self._invalid: + # Wait for a bit so the full error has a chance to arrive + time.sleep(1) + # Exit the process to make sure we're in a defined state again + self.terminate() + self._data.clear() raise InvalidLine(self._invalid) + + self._data.clear() if not self.is_running(): raise ProcessExited