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.
This commit is contained in:
Florian Bruhin 2015-11-09 07:43:48 +01:00
parent 8b016df023
commit 021ea444a1
2 changed files with 15 additions and 1 deletions

View File

@ -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()

View File

@ -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