Merge branch 'pytest30'

This commit is contained in:
Florian Bruhin 2016-08-23 09:03:24 +02:00
commit 64a61ce07f
43 changed files with 98 additions and 105 deletions

View File

@ -6,6 +6,8 @@ exclude = .*,__pycache__,resources.py
# E501: Line too long # E501: Line too long
# E402: module level import not at top of file # E402: module level import not at top of file
# E266: too many leading '#' for block comment # E266: too many leading '#' for block comment
# E731: do not assign a lambda expression, use a def
# (for pytest's __tracebackhide__)
# F401: Unused import # F401: Unused import
# N802: function name should be lowercase # N802: function name should be lowercase
# P101: format string does contain unindexed parameters # P101: format string does contain unindexed parameters
@ -27,7 +29,7 @@ exclude = .*,__pycache__,resources.py
# H301: one import per line # H301: one import per line
# H306: imports not in alphabetical order # H306: imports not in alphabetical order
ignore = ignore =
E128,E226,E265,E501,E402,E266, E128,E226,E265,E501,E402,E266,E731,
F401, F401,
N802, N802,
P101,P102,P103, P101,P102,P103,

View File

@ -68,6 +68,8 @@ max-args=10
valid-metaclass-classmethod-first-arg=cls valid-metaclass-classmethod-first-arg=cls
[TYPECHECK] [TYPECHECK]
# WORKAROUND for https://github.com/PyCQA/astroid/pull/357
ignored-modules=pytest
# MsgType added as WORKAROUND for # MsgType added as WORKAROUND for
# https://bitbucket.org/logilab/pylint/issues/690/ # https://bitbucket.org/logilab/pylint/issues/690/
# UnsetObject because pylint infers any objreg.get(...) as UnsetObject. # UnsetObject because pylint infers any objreg.get(...) as UnsetObject.

View File

@ -16,8 +16,8 @@ Mako==1.0.4
parse==1.6.6 parse==1.6.6
parse-type==0.3.4 parse-type==0.3.4
py==1.4.31 py==1.4.31
pytest==2.9.2 pytest==3.0.0
pytest-bdd==2.17.0 pytest-bdd==2.17.1
pytest-catchlog==1.2.2 pytest-catchlog==1.2.2
pytest-cov==2.3.1 pytest-cov==2.3.1
pytest-faulthandler==1.3.0 pytest-faulthandler==1.3.0

View File

@ -272,14 +272,14 @@ def main_check_all():
This makes sure the files have 100% coverage without running unrelated This makes sure the files have 100% coverage without running unrelated
tests. tests.
This runs py.test with the used executable, so check_coverage.py should be This runs pytest with the used executable, so check_coverage.py should be
called with something like ./.tox/py34/bin/python. called with something like ./.tox/py34/bin/python.
""" """
for test_file, src_file in PERFECT_FILES: for test_file, src_file in PERFECT_FILES:
if test_file is None: if test_file is None:
continue continue
subprocess.check_call( subprocess.check_call(
[sys.executable, '-m', 'py.test', '--cov', 'qutebrowser', [sys.executable, '-m', 'pytest', '--cov', 'qutebrowser',
'--cov-report', 'xml', test_file]) '--cov-report', 'xml', test_file])
with open('coverage.xml', encoding='utf-8') as f: with open('coverage.xml', encoding='utf-8') as f:
messages = check(f, [(test_file, src_file)]) messages = check(f, [(test_file, src_file)])

View File

@ -53,7 +53,7 @@ def temp_git_commit_file():
def get_build_exe_options(): def get_build_exe_options():
"""Get build_exe options with additional includes.""" """Get build_exe options with additional includes."""
opts = freeze.get_build_exe_options(skip_html=True) opts = freeze.get_build_exe_options(skip_html=True)
opts['includes'] += pytest.freeze_includes() # pylint: disable=no-member opts['includes'] += pytest.freeze_includes()
opts['includes'] += ['unittest.mock', 'PyQt5.QtTest', 'hypothesis', 'bs4', opts['includes'] += ['unittest.mock', 'PyQt5.QtTest', 'hypothesis', 'bs4',
'httpbin', 'jinja2.ext', 'cherrypy.wsgiserver', 'httpbin', 'jinja2.ext', 'cherrypy.wsgiserver',
'pstats'] 'pstats']

View File

@ -86,8 +86,8 @@ def pytest_collection_modifyitems(items):
For example: For example:
py.test -m "not gui" # run all tests except gui tests pytest -m "not gui" # run all tests except gui tests
py.test -m "gui" # run only gui tests pytest -m "gui" # run only gui tests
It also handles the platform specific markers by translating them to skipif It also handles the platform specific markers by translating them to skipif
markers. markers.
@ -133,6 +133,12 @@ def qapp(qapp):
return qapp return qapp
@pytest.fixture(scope='function', autouse=True)
def bug_workaround():
# WORKAROUND for https://github.com/pytest-dev/pytest/issues/1832
pass
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption('--qute-delay', action='store', default=0, type=int, parser.addoption('--qute-delay', action='store', default=0, type=int,
help="Delay between qutebrowser commands.") help="Delay between qutebrowser commands.")

View File

@ -430,9 +430,7 @@ def compare_session(request, quteproc, expected):
compared. compared.
""" """
if request.config.getoption('--qute-bdd-webengine'): if request.config.getoption('--qute-bdd-webengine'):
# pylint: disable=no-member
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
# pylint: enable=no-member
quteproc.compare_session(expected) quteproc.compare_session(expected)
@ -497,9 +495,7 @@ def check_open_tabs(quteproc, request, tabs):
It expects a list of URLs, with an optional "(active)" suffix. It expects a list of URLs, with an optional "(active)" suffix.
""" """
if request.config.getoption('--qute-bdd-webengine'): if request.config.getoption('--qute-bdd-webengine'):
# pylint: disable=no-member
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
# pylint: enable=no-member
session = quteproc.get_session() session = quteproc.get_session()
active_suffix = ' (active)' active_suffix = ' (active)'
tabs = tabs.splitlines() tabs = tabs.splitlines()
@ -556,9 +552,7 @@ def _get_scroll_values(quteproc):
r"(?P<direction>horizontally|vertically)")) r"(?P<direction>horizontally|vertically)"))
def check_scrolled(request, quteproc, direction): def check_scrolled(request, quteproc, direction):
if request.config.getoption('--qute-bdd-webengine'): if request.config.getoption('--qute-bdd-webengine'):
# pylint: disable=no-member
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
# pylint: enable=no-member
x, y = _get_scroll_values(quteproc) x, y = _get_scroll_values(quteproc)
if direction == 'horizontally': if direction == 'horizontally':
assert x != 0 assert x != 0
@ -571,9 +565,7 @@ def check_scrolled(request, quteproc, direction):
@bdd.then("the page should not be scrolled") @bdd.then("the page should not be scrolled")
def check_not_scrolled(request, quteproc): def check_not_scrolled(request, quteproc):
if request.config.getoption('--qute-bdd-webengine'): if request.config.getoption('--qute-bdd-webengine'):
# pylint: disable=no-member
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
# pylint: enable=no-member
x, y = _get_scroll_values(quteproc) x, y = _get_scroll_values(quteproc)
assert x == 0 assert x == 0
assert y == 0 assert y == 0

View File

@ -25,9 +25,7 @@ bdd.scenarios('marks.feature')
@bdd.then(bdd.parsers.parse("the page should be scrolled to {x} {y}")) @bdd.then(bdd.parsers.parse("the page should be scrolled to {x} {y}"))
def check_y(request, quteproc, x, y): def check_y(request, quteproc, x, y):
if request.config.getoption('--qute-bdd-webengine'): if request.config.getoption('--qute-bdd-webengine'):
# pylint: disable=no-member
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
# pylint: enable=no-member
data = quteproc.get_session() data = quteproc.get_session()
pos = data['windows'][0]['tabs'][0]['history'][-1]['scroll-pos'] pos = data['windows'][0]['tabs'][0]['history'][-1]['scroll-pos']
assert int(x) == pos['x'] assert int(x) == pos['x']

View File

@ -46,9 +46,6 @@ instance_counter = itertools.count()
def is_ignored_qt_message(message): def is_ignored_qt_message(message):
"""Check if the message is listed in qt_log_ignore.""" """Check if the message is listed in qt_log_ignore."""
# pylint: disable=no-member
# WORKAROUND for https://bitbucket.org/logilab/pylint/issues/717/
# we should switch to generated-members after that
regexes = pytest.config.getini('qt_log_ignore') regexes = pytest.config.getini('qt_log_ignore')
for regex in regexes: for regex in regexes:
if re.match(regex, message): if re.match(regex, message):
@ -277,7 +274,7 @@ class QuteProc(testprocess.Process):
if path.startswith('about:') or path.startswith('qute:'): if path.startswith('about:') or path.startswith('qute:'):
return path return path
else: else:
httpbin = self.request.getfuncargvalue('httpbin') httpbin = self.request.getfixturevalue('httpbin')
return '{}://localhost:{}/{}'.format( return '{}://localhost:{}/{}'.format(
'https' if https else 'http', 'https' if https else 'http',
httpbin.port if port is None else port, httpbin.port if port is None else port,
@ -295,6 +292,8 @@ class QuteProc(testprocess.Process):
def wait_for(self, timeout=None, **kwargs): def wait_for(self, timeout=None, **kwargs):
"""Extend wait_for to add divisor if a test is xfailing.""" """Extend wait_for to add divisor if a test is xfailing."""
__tracebackhide__ = (lambda e:
e.errisinstance(testprocess.WaitForTimeout))
xfail = self.request.node.get_marker('xfail') xfail = self.request.node.get_marker('xfail')
if xfail and xfail.args[0]: if xfail and xfail.args[0]:
kwargs['divisor'] = 10 kwargs['divisor'] = 10
@ -347,7 +346,7 @@ class QuteProc(testprocess.Process):
def after_test(self): def after_test(self):
"""Handle unexpected/skip logging and clean up after each test.""" """Handle unexpected/skip logging and clean up after each test."""
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception)
bad_msgs = [msg for msg in self._data bad_msgs = [msg for msg in self._data
if self._is_error_logline(msg) and not msg.expected] if self._is_error_logline(msg) and not msg.expected]
@ -464,7 +463,8 @@ class QuteProc(testprocess.Process):
def wait_for_load_finished_url(self, url, *, timeout=None, def wait_for_load_finished_url(self, url, *, timeout=None,
load_status='success'): load_status='success'):
"""Wait until a URL has finished loading.""" """Wait until a URL has finished loading."""
__tracebackhide__ = True __tracebackhide__ = (lambda e: e.errisinstance(
testprocess.WaitForTimeout))
if timeout is None: if timeout is None:
if 'CI' in os.environ: if 'CI' in os.environ:
@ -496,7 +496,8 @@ class QuteProc(testprocess.Process):
def wait_for_load_finished(self, path, *, port=None, https=False, def wait_for_load_finished(self, path, *, port=None, https=False,
timeout=None, load_status='success'): timeout=None, load_status='success'):
"""Wait until a path has finished loading.""" """Wait until a path has finished loading."""
__tracebackhide__ = True __tracebackhide__ = (lambda e: e.errisinstance(
testprocess.WaitForTimeout))
url = self.path_to_url(path, port=port, https=https) url = self.path_to_url(path, port=port, https=https)
self.wait_for_load_finished_url(url, timeout=timeout, self.wait_for_load_finished_url(url, timeout=timeout,
load_status=load_status) load_status=load_status)
@ -562,7 +563,7 @@ class QuteProc(testprocess.Process):
partial_compare is used, which means only the keys/values listed will partial_compare is used, which means only the keys/values listed will
be compared. be compared.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception)
# Translate ... to ellipsis in YAML. # Translate ... to ellipsis in YAML.
loader = yaml.SafeLoader(expected) loader = yaml.SafeLoader(expected)
loader.add_constructor('!ellipsis', lambda loader, node: ...) loader.add_constructor('!ellipsis', lambda loader, node: ...)
@ -606,7 +607,7 @@ def _xpath_escape(text):
return 'concat({})'.format(', '.join(parts)) return 'concat({})'.format(', '.join(parts))
@pytest.yield_fixture(scope='module') @pytest.fixture(scope='module')
def quteproc_process(qapp, httpbin, request): def quteproc_process(qapp, httpbin, request):
"""Fixture for qutebrowser process which is started once per file.""" """Fixture for qutebrowser process which is started once per file."""
# Passing request so it has an initial config # Passing request so it has an initial config
@ -616,7 +617,7 @@ def quteproc_process(qapp, httpbin, request):
proc.terminate() proc.terminate()
@pytest.yield_fixture @pytest.fixture
def quteproc(quteproc_process, httpbin, request): def quteproc(quteproc_process, httpbin, request):
"""Per-test qutebrowser fixture which uses the per-file process.""" """Per-test qutebrowser fixture which uses the per-file process."""
request.node._quteproc_log = quteproc_process.captured_log request.node._quteproc_log = quteproc_process.captured_log
@ -626,7 +627,7 @@ def quteproc(quteproc_process, httpbin, request):
quteproc_process.after_test() quteproc_process.after_test()
@pytest.yield_fixture @pytest.fixture
def quteproc_new(qapp, httpbin, request): def quteproc_new(qapp, httpbin, request):
"""Per-test qutebrowser process to test invocations.""" """Per-test qutebrowser process to test invocations."""
proc = QuteProc(request) proc = QuteProc(request)

View File

@ -70,7 +70,7 @@ class FakeRequest:
self.config = config self.config = config
self._httpbin = httpbin self._httpbin = httpbin
def getfuncargvalue(self, name): def getfixturevalue(self, name):
assert name == 'httpbin' assert name == 'httpbin'
return self._httpbin return self._httpbin

View File

@ -102,21 +102,21 @@ class NoReadyPythonProcess(PythonProcess):
return (sys.executable, ['-c', ';'.join(code)]) return (sys.executable, ['-c', ';'.join(code)])
@pytest.yield_fixture @pytest.fixture
def pyproc(): def pyproc():
proc = PythonProcess() proc = PythonProcess()
yield proc yield proc
proc.terminate() proc.terminate()
@pytest.yield_fixture @pytest.fixture
def quit_pyproc(): def quit_pyproc():
proc = QuitPythonProcess() proc = QuitPythonProcess()
yield proc yield proc
proc.terminate() proc.terminate()
@pytest.yield_fixture @pytest.fixture
def noready_pyproc(): def noready_pyproc():
proc = NoReadyPythonProcess() proc = NoReadyPythonProcess()
yield proc yield proc

View File

@ -77,7 +77,6 @@ class Line:
def _render_log(data, threshold=100): def _render_log(data, threshold=100):
"""Shorten the given log without -v and convert to a string.""" """Shorten the given log without -v and convert to a string."""
# pylint: disable=no-member
data = [str(d) for d in data] data = [str(d) for d in data]
is_exception = any('Traceback (most recent call last):' in line is_exception = any('Traceback (most recent call last):' in line
for line in data) for line in data)
@ -109,7 +108,6 @@ def pytest_runtest_makereport(item, call):
# actually a tuple. This is handled similarily in pytest-qt too. # actually a tuple. This is handled similarily in pytest-qt too.
return return
# pylint: disable=no-member
if pytest.config.getoption('--capture') == 'no': if pytest.config.getoption('--capture') == 'no':
# Already printed live # Already printed live
return return
@ -153,7 +151,6 @@ class Process(QObject):
def _log(self, line): def _log(self, line):
"""Add the given line to the captured log output.""" """Add the given line to the captured log output."""
# pylint: disable=no-member
if pytest.config.getoption('--capture') == 'no': if pytest.config.getoption('--capture') == 'no':
print(line) print(line)
self.captured_log.append(line) self.captured_log.append(line)
@ -279,7 +276,7 @@ class Process(QObject):
Also checks self._invalid so the test counts as failed if there were Also checks self._invalid so the test counts as failed if there were
unexpected output lines earlier. unexpected output lines earlier.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(ProcessExited)
self.captured_log = [] self.captured_log = []
if self._invalid: if self._invalid:
# Wait for a bit so the full error has a chance to arrive # Wait for a bit so the full error has a chance to arrive
@ -338,7 +335,6 @@ class Process(QObject):
Return: either the found line or None. Return: either the found line or None.
""" """
__tracebackhide__ = True
for line in self._data: for line in self._data:
matches = [] matches = []
@ -362,7 +358,7 @@ class Process(QObject):
Called via wait_for. Called via wait_for.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
message = kwargs.get('message', None) message = kwargs.get('message', None)
if message is not None: if message is not None:
elided = quteutils.elide(repr(message), 50) elided = quteutils.elide(repr(message), 50)
@ -441,7 +437,7 @@ class Process(QObject):
Return: Return:
The matched line. The matched line.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
if timeout is None: if timeout is None:
if do_skip: if do_skip:
@ -471,7 +467,7 @@ class Process(QObject):
If nothing is found in the log, we wait for delay ms to make sure If nothing is found in the log, we wait for delay ms to make sure
nothing arrives. nothing arrives.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(BlacklistedMessageError)
try: try:
line = self.wait_for(timeout=delay, override_waited_for=True, line = self.wait_for(timeout=delay, override_waited_for=True,
**kwargs) **kwargs)

View File

@ -167,7 +167,7 @@ class WebserverProcess(testprocess.Process):
self.proc.waitForFinished() self.proc.waitForFinished()
@pytest.yield_fixture(scope='session', autouse=True) @pytest.fixture(scope='session', autouse=True)
def httpbin(qapp): def httpbin(qapp):
"""Fixture for an httpbin object which ensures clean setup/teardown.""" """Fixture for an httpbin object which ensures clean setup/teardown."""
httpbin = WebserverProcess('webserver_sub') httpbin = WebserverProcess('webserver_sub')
@ -176,7 +176,7 @@ def httpbin(qapp):
httpbin.cleanup() httpbin.cleanup()
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def httpbin_after_test(httpbin, request): def httpbin_after_test(httpbin, request):
"""Fixture to clean httpbin request list after each test.""" """Fixture to clean httpbin request list after each test."""
request.node._httpbin_log = httpbin.captured_log request.node._httpbin_log = httpbin.captured_log
@ -184,7 +184,7 @@ def httpbin_after_test(httpbin, request):
httpbin.after_test() httpbin.after_test()
@pytest.yield_fixture @pytest.fixture
def ssl_server(request, qapp): def ssl_server(request, qapp):
"""Fixture for a webserver with a self-signed SSL certificate. """Fixture for a webserver with a self-signed SSL certificate.

View File

@ -54,8 +54,6 @@ def turn_off_logging():
def main(): def main():
ssl_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), ssl_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'..', 'data', 'ssl') '..', 'data', 'ssl')
# WORKAROUND for https://github.com/PyCQA/pylint/issues/399
# pylint: disable=no-member, useless-suppression
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain(os.path.join(ssl_dir, 'cert.pem'), context.load_cert_chain(os.path.join(ssl_dir, 'cert.pem'),
os.path.join(ssl_dir, 'key.pem')) os.path.join(ssl_dir, 'key.pem'))

View File

@ -93,9 +93,7 @@ def test_hints(test_name, zoom_text_only, zoom_level, find_implementation,
parsed = _parse_file(test_name) parsed = _parse_file(test_name)
if parsed.qtwebengine_todo is not None and webengine: if parsed.qtwebengine_todo is not None and webengine:
# pylint: disable=no-member
pytest.xfail("QtWebEngine TODO: {}".format(parsed.qtwebengine_todo)) pytest.xfail("QtWebEngine TODO: {}".format(parsed.qtwebengine_todo))
# pylint: enable=no-member
url_path = 'data/hints/html/{}'.format(test_name) url_path = 'data/hints/html/{}'.format(test_name)
quteproc.open_path(url_path) quteproc.open_path(url_path)

View File

@ -49,10 +49,8 @@ def test_insert_mode(file_name, elem_id, source, input_text, auto_insert,
quteproc.press_keys(input_text) quteproc.press_keys(input_text)
elif source == 'clipboard': elif source == 'clipboard':
if request.config.getoption('--qute-bdd-webengine'): if request.config.getoption('--qute-bdd-webengine'):
# pylint: disable=no-member
pytest.xfail(reason="QtWebEngine TODO: :insert-text is not " pytest.xfail(reason="QtWebEngine TODO: :insert-text is not "
"implemented") "implemented")
# pylint: enable=no-member
quteproc.send_cmd(':debug-set-fake-clipboard "{}"'.format(input_text)) quteproc.send_cmd(':debug-set-fake-clipboard "{}"'.format(input_text))
quteproc.send_cmd(':insert-text {clipboard}') quteproc.send_cmd(':insert-text {clipboard}')

View File

@ -41,7 +41,6 @@ def test_smoke(cmd, capfd):
if e.returncode == -signal.SIGSEGV: if e.returncode == -signal.SIGSEGV:
_out, err = capfd.readouterr() _out, err = capfd.readouterr()
assert 'Uncaught exception' not in err assert 'Uncaught exception' not in err
# pylint: disable=no-member
# https://github.com/The-Compiler/qutebrowser/issues/1387 # https://github.com/The-Compiler/qutebrowser/issues/1387
pytest.xfail("Ignoring segfault on exit...") pytest.xfail("Ignoring segfault on exit...")
else: else:

View File

@ -137,7 +137,7 @@ def fake_statusbar(qtbot):
return statusbar return statusbar
@pytest.yield_fixture @pytest.fixture
def win_registry(): def win_registry():
"""Fixture providing a window registry for win_id 0 and 1.""" """Fixture providing a window registry for win_id 0 and 1."""
helper = WinRegistryHelper() helper = WinRegistryHelper()
@ -146,7 +146,7 @@ def win_registry():
helper.cleanup() helper.cleanup()
@pytest.yield_fixture @pytest.fixture
def tab_registry(win_registry): def tab_registry(win_registry):
"""Fixture providing a tab registry for win_id 0.""" """Fixture providing a tab registry for win_id 0."""
registry = objreg.ObjectRegistry() registry = objreg.ObjectRegistry()
@ -203,7 +203,7 @@ def cmdline_test(request):
return request.param return request.param
@pytest.yield_fixture @pytest.fixture
def config_stub(stubs): def config_stub(stubs):
"""Fixture which provides a fake config object.""" """Fixture which provides a fake config object."""
stub = stubs.ConfigStub() stub = stubs.ConfigStub()
@ -212,7 +212,7 @@ def config_stub(stubs):
objreg.delete('config') objreg.delete('config')
@pytest.yield_fixture @pytest.fixture
def default_config(): def default_config():
"""Fixture that provides and registers an empty default config object.""" """Fixture that provides and registers an empty default config object."""
config_obj = config.ConfigManager() config_obj = config.ConfigManager()
@ -222,7 +222,7 @@ def default_config():
objreg.delete('config') objreg.delete('config')
@pytest.yield_fixture @pytest.fixture
def key_config_stub(stubs): def key_config_stub(stubs):
"""Fixture which provides a fake key config object.""" """Fixture which provides a fake key config object."""
stub = stubs.KeyConfigStub() stub = stubs.KeyConfigStub()
@ -231,7 +231,7 @@ def key_config_stub(stubs):
objreg.delete('key-config') objreg.delete('key-config')
@pytest.yield_fixture @pytest.fixture
def host_blocker_stub(stubs): def host_blocker_stub(stubs):
"""Fixture which provides a fake host blocker object.""" """Fixture which provides a fake host blocker object."""
stub = stubs.HostBlockerStub() stub = stubs.HostBlockerStub()
@ -240,7 +240,7 @@ def host_blocker_stub(stubs):
objreg.delete('host-blocker') objreg.delete('host-blocker')
@pytest.yield_fixture @pytest.fixture
def quickmark_manager_stub(stubs): def quickmark_manager_stub(stubs):
"""Fixture which provides a fake quickmark manager object.""" """Fixture which provides a fake quickmark manager object."""
stub = stubs.QuickmarkManagerStub() stub = stubs.QuickmarkManagerStub()
@ -249,7 +249,7 @@ def quickmark_manager_stub(stubs):
objreg.delete('quickmark-manager') objreg.delete('quickmark-manager')
@pytest.yield_fixture @pytest.fixture
def bookmark_manager_stub(stubs): def bookmark_manager_stub(stubs):
"""Fixture which provides a fake bookmark manager object.""" """Fixture which provides a fake bookmark manager object."""
stub = stubs.BookmarkManagerStub() stub = stubs.BookmarkManagerStub()
@ -258,7 +258,7 @@ def bookmark_manager_stub(stubs):
objreg.delete('bookmark-manager') objreg.delete('bookmark-manager')
@pytest.yield_fixture @pytest.fixture
def web_history_stub(stubs): def web_history_stub(stubs):
"""Fixture which provides a fake web-history object.""" """Fixture which provides a fake web-history object."""
stub = stubs.WebHistoryStub() stub = stubs.WebHistoryStub()
@ -267,7 +267,7 @@ def web_history_stub(stubs):
objreg.delete('web-history') objreg.delete('web-history')
@pytest.yield_fixture @pytest.fixture
def session_manager_stub(stubs): def session_manager_stub(stubs):
"""Fixture which provides a fake web-history object.""" """Fixture which provides a fake web-history object."""
stub = stubs.SessionManagerStub() stub = stubs.SessionManagerStub()
@ -276,7 +276,7 @@ def session_manager_stub(stubs):
objreg.delete('session-manager') objreg.delete('session-manager')
@pytest.yield_fixture @pytest.fixture
def tabbed_browser_stubs(stubs, win_registry): def tabbed_browser_stubs(stubs, win_registry):
"""Fixture providing a fake tabbed-browser object on win_id 0 and 1.""" """Fixture providing a fake tabbed-browser object on win_id 0 and 1."""
win_registry.add_window(1) win_registry.add_window(1)
@ -288,7 +288,7 @@ def tabbed_browser_stubs(stubs, win_registry):
objreg.delete('tabbed-browser', scope='window', window=1) objreg.delete('tabbed-browser', scope='window', window=1)
@pytest.yield_fixture @pytest.fixture
def app_stub(stubs): def app_stub(stubs):
"""Fixture which provides a fake app object.""" """Fixture which provides a fake app object."""
stub = stubs.ApplicationStub() stub = stubs.ApplicationStub()
@ -297,7 +297,7 @@ def app_stub(stubs):
objreg.delete('app') objreg.delete('app')
@pytest.yield_fixture @pytest.fixture
def status_command_stub(stubs, qtbot, win_registry): def status_command_stub(stubs, qtbot, win_registry):
"""Fixture which provides a fake status-command object.""" """Fixture which provides a fake status-command object."""
cmd = stubs.StatusBarCommandStub() cmd = stubs.StatusBarCommandStub()
@ -387,7 +387,7 @@ def fake_keyevent_factory():
return fake_keyevent return fake_keyevent
@pytest.yield_fixture @pytest.fixture
def cookiejar_and_cache(stubs): def cookiejar_and_cache(stubs):
"""Fixture providing a fake cookie jar and cache.""" """Fixture providing a fake cookie jar and cache."""
jar = QNetworkCookieJar() jar = QNetworkCookieJar()
@ -414,7 +414,7 @@ def py_proc():
return func return func
@pytest.yield_fixture @pytest.fixture
def fake_save_manager(): def fake_save_manager():
"""Create a mock of save-manager and register it into objreg.""" """Create a mock of save-manager and register it into objreg."""
fake_save_manager = unittest.mock.Mock(spec=savemanager.SaveManager) fake_save_manager = unittest.mock.Mock(spec=savemanager.SaveManager)
@ -423,7 +423,7 @@ def fake_save_manager():
objreg.delete('save-manager') objreg.delete('save-manager')
@pytest.yield_fixture @pytest.fixture
def fake_args(): def fake_args():
ns = types.SimpleNamespace() ns = types.SimpleNamespace()
objreg.register('args', ns) objreg.register('args', ns)
@ -431,7 +431,7 @@ def fake_args():
objreg.delete('args') objreg.delete('args')
@pytest.yield_fixture @pytest.fixture
def mode_manager(win_registry, config_stub, qapp): def mode_manager(win_registry, config_stub, qapp):
config_stub.data.update({'input': {'forward-unbound-keys': 'auto'}}) config_stub.data.update({'input': {'forward-unbound-keys': 'auto'}})
mm = modeman.ModeManager(0) mm = modeman.ModeManager(0)

View File

@ -70,7 +70,7 @@ class LogFailHandler(logging.Handler):
record.getMessage())) record.getMessage()))
@pytest.yield_fixture(scope='session', autouse=True) @pytest.fixture(scope='session', autouse=True)
def fail_on_logging(): def fail_on_logging():
handler = LogFailHandler() handler = LogFailHandler()
logging.getLogger().addHandler(handler) logging.getLogger().addHandler(handler)

View File

@ -45,6 +45,7 @@ def test_partial_compare_equal(val1, val2):
({1: 1}, {1: [1]}, "Different types (int, list) -> False"), ({1: 1}, {1: [1]}, "Different types (int, list) -> False"),
({'a': [1, 2, 3]}, {'a': [..., 3]}, "2 != 3"), ({'a': [1, 2, 3]}, {'a': [..., 3]}, "2 != 3"),
("foo*baz", "foobarbaz", "'foo*baz' != 'foobarbaz' (pattern matching)"), ("foo*baz", "foobarbaz", "'foo*baz' != 'foobarbaz' (pattern matching)"),
(23.42, 13.37, "23.42 != 13.37 (float comparison)"),
]) ])
def test_partial_compare_not_equal(val1, val2, error): def test_partial_compare_not_equal(val1, val2, error):
outcome = utils.partial_compare(val1, val2) outcome = utils.partial_compare(val1, val2)

View File

@ -26,6 +26,8 @@ import re
import pprint import pprint
import os.path import os.path
import pytest
class PartialCompareOutcome: class PartialCompareOutcome:
@ -84,7 +86,7 @@ def _partial_compare_list(val1, val2, *, indent):
def _partial_compare_float(val1, val2, *, indent): def _partial_compare_float(val1, val2, *, indent):
if abs(val1 - val2) < 0.00001: if val1 == pytest.approx(val2):
return PartialCompareOutcome() return PartialCompareOutcome()
return PartialCompareOutcome("{!r} != {!r} (float comparison)".format( return PartialCompareOutcome("{!r} != {!r} (float comparison)".format(

View File

@ -96,7 +96,7 @@ class FakeDownloadManager:
return download_item return download_item
@pytest.yield_fixture @pytest.fixture
def download_stub(win_registry): def download_stub(win_registry):
"""Register a FakeDownloadManager.""" """Register a FakeDownloadManager."""
stub = FakeDownloadManager() stub = FakeDownloadManager()

View File

@ -32,7 +32,7 @@ ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd'])
pytestmark = pytest.mark.usefixtures('cookiejar_and_cache') pytestmark = pytest.mark.usefixtures('cookiejar_and_cache')
@pytest.yield_fixture @pytest.fixture
def objects(qtbot, default_config, key_config_stub, tab_registry, def objects(qtbot, default_config, key_config_stub, tab_registry,
host_blocker_stub): host_blocker_stub):
"""Fixture providing a CommandDispatcher and a fake TabbedBrowser.""" """Fixture providing a CommandDispatcher and a fake TabbedBrowser."""

View File

@ -83,7 +83,7 @@ def objects():
return Objects(signal_filter=signal_filter, signaller=signaller) return Objects(signal_filter=signal_filter, signaller=signaller)
@pytest.yield_fixture @pytest.fixture
def tabbed_browser(win_registry): def tabbed_browser(win_registry):
tb = FakeTabbedBrowser() tb = FakeTabbedBrowser()
objreg.register('tabbed-browser', tb, scope='window', window=0) objreg.register('tabbed-browser', tb, scope='window', window=0)

View File

@ -58,7 +58,7 @@ def view(qtbot, config_stub, request):
return v return v
@pytest.yield_fixture(params=['webkit', 'webengine']) @pytest.fixture(params=['webkit', 'webengine'])
def tab(request, default_config, qtbot, tab_registry, cookiejar_and_cache): def tab(request, default_config, qtbot, tab_registry, cookiejar_and_cache):
if PYQT_VERSION < 0x050600: if PYQT_VERSION < 0x050600:
pytest.skip('Causes segfaults, see #1638') pytest.skip('Causes segfaults, see #1638')

View File

@ -366,7 +366,7 @@ def test_entry_str(entry, expected):
assert str(entry) == expected assert str(entry) == expected
@pytest.yield_fixture @pytest.fixture
def hist_interface(): def hist_interface():
entry = history.Entry(atime=0, url=QUrl('http://www.example.com/'), entry = history.Entry(atime=0, url=QUrl('http://www.example.com/'),
title='example') title='example')

View File

@ -46,7 +46,7 @@ class TestArgumentParser:
def parser(self): def parser(self):
return argparser.ArgumentParser('foo') return argparser.ArgumentParser('foo')
@pytest.yield_fixture @pytest.fixture
def tabbed_browser(self, win_registry): def tabbed_browser(self, win_registry):
tb = FakeTabbedBrowser() tb = FakeTabbedBrowser()
objreg.register('tabbed-browser', tb, scope='window', window=0) objreg.register('tabbed-browser', tb, scope='window', window=0)

View File

@ -38,7 +38,7 @@ def guiprocess_message_mock(message_mock):
@pytest.mark.posix @pytest.mark.posix
class TestQtFIFOReader: class TestQtFIFOReader:
@pytest.yield_fixture @pytest.fixture
def reader(self, tmpdir, qapp): def reader(self, tmpdir, qapp):
fifo_path = str(tmpdir / 'fifo') fifo_path = str(tmpdir / 'fifo')
os.mkfifo(fifo_path) # pylint: disable=no-member,useless-suppression os.mkfifo(fifo_path) # pylint: disable=no-member,useless-suppression

View File

@ -411,7 +411,7 @@ class TestConfigInit:
"""Test initializing of the config.""" """Test initializing of the config."""
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def patch(self, fake_args): def patch(self, fake_args):
objreg.register('app', QObject()) objreg.register('app', QObject())
objreg.register('save-manager', mock.MagicMock()) objreg.register('save-manager', mock.MagicMock())

View File

@ -26,7 +26,7 @@ from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def enable_caret_browsing(qapp): def enable_caret_browsing(qapp):
"""Fixture to enable caret browsing globally.""" """Fixture to enable caret browsing globally."""
settings = QWebSettings.globalSettings() settings = QWebSettings.globalSettings()

View File

@ -35,7 +35,7 @@ BINDINGS = {'test': {'<Ctrl-a>': 'ctrla',
'normal': {'a': 'a', 'ba': 'ba'}} 'normal': {'a': 'a', 'ba': 'ba'}}
@pytest.yield_fixture @pytest.fixture
def fake_keyconfig(): def fake_keyconfig():
"""Create a mock of a KeyConfiguration and register it into objreg.""" """Create a mock of a KeyConfiguration and register it into objreg."""
bindings = dict(BINDINGS) # so the bindings can be changed later bindings = dict(BINDINGS) # so the bindings can be changed later

View File

@ -33,7 +33,7 @@ from qutebrowser.utils import utils
CONFIG = {'input': {'timeout': 100}} CONFIG = {'input': {'timeout': 100}}
@pytest.yield_fixture @pytest.fixture
def keyparser(): def keyparser():
"""Fixture providing a BaseKeyParser supporting count/chains.""" """Fixture providing a BaseKeyParser supporting count/chains."""
kp = basekeyparser.BaseKeyParser( kp = basekeyparser.BaseKeyParser(

View File

@ -27,7 +27,7 @@ from qutebrowser.mainwindow.statusbar.prompt import Prompt
from qutebrowser.utils import objreg from qutebrowser.utils import objreg
@pytest.yield_fixture @pytest.fixture
def prompt(qtbot, win_registry): def prompt(qtbot, win_registry):
prompt = Prompt(0) prompt = Prompt(0)
qtbot.addWidget(prompt) qtbot.addWidget(prompt)

View File

@ -41,7 +41,7 @@ def patch_things(config_stub, message_mock, monkeypatch, stubs):
monkeypatch.setattr('qutebrowser.misc.editor.config', config_stub) monkeypatch.setattr('qutebrowser.misc.editor.config', config_stub)
@pytest.yield_fixture @pytest.fixture
def editor(): def editor():
ed = editormod.ExternalEditor(0) ed = editormod.ExternalEditor(0)
ed.editing_finished = mock.Mock() ed.editing_finished = mock.Mock()

View File

@ -34,7 +34,7 @@ def guiprocess_message_mock(message_mock):
return message_mock return message_mock
@pytest.yield_fixture() @pytest.fixture()
def proc(qtbot): def proc(qtbot):
"""A fixture providing a GUIProcess and cleaning it up after the test.""" """A fixture providing a GUIProcess and cleaning it up after the test."""
p = guiprocess.GUIProcess(0, 'testprocess') p = guiprocess.GUIProcess(0, 'testprocess')

View File

@ -45,13 +45,13 @@ from helpers import stubs
pytestmark = pytest.mark.usefixtures('qapp') pytestmark = pytest.mark.usefixtures('qapp')
@pytest.yield_fixture() @pytest.fixture()
def short_tmpdir(): def short_tmpdir():
with tempfile.TemporaryDirectory() as tdir: with tempfile.TemporaryDirectory() as tdir:
yield py.path.local(tdir) # pylint: disable=no-member yield py.path.local(tdir) # pylint: disable=no-member
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def shutdown_server(): def shutdown_server():
"""If ipc.send_or_listen was called, make sure to shut server down.""" """If ipc.send_or_listen was called, make sure to shut server down."""
yield yield
@ -63,7 +63,7 @@ def shutdown_server():
server.shutdown() server.shutdown()
@pytest.yield_fixture @pytest.fixture
def ipc_server(qapp, qtbot): def ipc_server(qapp, qtbot):
server = ipc.IPCServer('qute-test') server = ipc.IPCServer('qute-test')
yield server yield server
@ -77,7 +77,7 @@ def ipc_server(qapp, qtbot):
pass pass
@pytest.yield_fixture @pytest.fixture
def qlocalserver(qapp): def qlocalserver(qapp):
server = QLocalServer() server = QLocalServer()
yield server yield server
@ -85,7 +85,7 @@ def qlocalserver(qapp):
server.deleteLater() server.deleteLater()
@pytest.yield_fixture @pytest.fixture
def qlocalsocket(qapp): def qlocalsocket(qapp):
socket = QLocalSocket() socket = QLocalSocket()
yield socket yield socket
@ -447,7 +447,7 @@ class TestHandleConnection:
assert "We can read a line immediately." in all_msgs assert "We can read a line immediately." in all_msgs
@pytest.yield_fixture @pytest.fixture
def connected_socket(qtbot, qlocalsocket, ipc_server): def connected_socket(qtbot, qlocalsocket, ipc_server):
if sys.platform == 'darwin': if sys.platform == 'darwin':
pytest.skip("Skipping connected_socket test - " pytest.skip("Skipping connected_socket test - "
@ -654,7 +654,7 @@ class TestSendOrListen:
setattr(m, attr, getattr(QLocalSocket, attr)) setattr(m, attr, getattr(QLocalSocket, attr))
return m return m
@pytest.yield_fixture @pytest.fixture
def legacy_server(self, args): def legacy_server(self, args):
legacy_name = ipc._get_socketname(args.basedir, legacy=True) legacy_name = ipc._get_socketname(args.basedir, legacy=True)
legacy_server = ipc.IPCServer(legacy_name) legacy_server = ipc.IPCServer(legacy_name)

View File

@ -31,7 +31,7 @@ class TestCommandLineEdit:
"""Tests for CommandLineEdit widget.""" """Tests for CommandLineEdit widget."""
@pytest.yield_fixture @pytest.fixture
def cmd_edit(self, qtbot): def cmd_edit(self, qtbot):
"""Fixture to initialize a CommandLineEdit.""" """Fixture to initialize a CommandLineEdit."""
cmd_edit = miscwidgets.CommandLineEdit(None) cmd_edit = miscwidgets.CommandLineEdit(None)

View File

@ -50,7 +50,7 @@ def sess_man():
class TestInit: class TestInit:
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def cleanup(self): def cleanup(self):
yield yield
objreg.delete('session-manager') objreg.delete('session-manager')
@ -313,7 +313,7 @@ class FakeTabbedBrowser:
return 1 return 1
@pytest.yield_fixture @pytest.fixture
def fake_windows(win_registry, stubs, monkeypatch, qtbot): def fake_windows(win_registry, stubs, monkeypatch, qtbot):
"""Fixture which provides two fake main windows and tabbedbrowsers.""" """Fixture which provides two fake main windows and tabbedbrowsers."""
win_registry.add_window(1) win_registry.add_window(1)
@ -400,14 +400,14 @@ def test_get_session_name(config_stub, sess_man, arg, config, current,
class TestSave: class TestSave:
@pytest.yield_fixture @pytest.fixture
def state_config(self): def state_config(self):
state = {'general': {}} state = {'general': {}}
objreg.register('state-config', state) objreg.register('state-config', state)
yield state yield state
objreg.delete('state-config') objreg.delete('state-config')
@pytest.yield_fixture @pytest.fixture
def fake_history(self, win_registry, stubs, monkeypatch, webview): def fake_history(self, win_registry, stubs, monkeypatch, webview):
"""Fixture which provides a window with a fake history.""" """Fixture which provides a window with a fake history."""
win = FakeMainWindow(b'fake-geometry-0', win_id=0) win = FakeMainWindow(b'fake-geometry-0', win_id=0)

View File

@ -32,7 +32,7 @@ from qutebrowser.utils import log
from qutebrowser.misc import utilcmds from qutebrowser.misc import utilcmds
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def restore_loggers(): def restore_loggers():
"""Fixture to save/restore the logging state. """Fixture to save/restore the logging state.

View File

@ -375,7 +375,7 @@ class TestSavefileOpen:
## Tests with a mock testing that the needed methods are called. ## Tests with a mock testing that the needed methods are called.
@pytest.yield_fixture @pytest.fixture
def qsavefile_mock(self, mocker): def qsavefile_mock(self, mocker):
"""Mock for QSaveFile.""" """Mock for QSaveFile."""
m = mocker.patch('qutebrowser.utils.qtutils.QSaveFile') m = mocker.patch('qutebrowser.utils.qtutils.QSaveFile')
@ -538,7 +538,7 @@ if test_file is not None and sys.platform != 'darwin':
# Those are not run on OS X because that seems to cause a hang sometimes. # Those are not run on OS X because that seems to cause a hang sometimes.
@pytest.yield_fixture(scope='session', autouse=True) @pytest.fixture(scope='session', autouse=True)
def clean_up_python_testfile(): def clean_up_python_testfile():
"""Clean up the python testfile after tests if tests didn't.""" """Clean up the python testfile after tests if tests didn't."""
yield yield
@ -641,7 +641,7 @@ class TestPyQIODevice:
"""Tests for PyQIODevice.""" """Tests for PyQIODevice."""
@pytest.yield_fixture @pytest.fixture
def pyqiodev(self): def pyqiodev(self):
"""Fixture providing a PyQIODevice with a QByteArray to test.""" """Fixture providing a PyQIODevice with a QByteArray to test."""
data = QByteArray() data = QByteArray()

View File

@ -32,7 +32,7 @@ import pytest
from qutebrowser.utils import standarddir from qutebrowser.utils import standarddir
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def change_qapp_name(qapp): def change_qapp_name(qapp):
"""Change the name of the QApplication instance. """Change the name of the QApplication instance.
@ -52,7 +52,7 @@ def no_cachedir_tag(monkeypatch):
lambda: None) lambda: None)
@pytest.yield_fixture @pytest.fixture
def reset_standarddir(no_cachedir_tag): def reset_standarddir(no_cachedir_tag):
"""Clean up standarddir arguments before and after each test.""" """Clean up standarddir arguments before and after each test."""
standarddir.init(None) standarddir.init(None)

View File

@ -589,7 +589,7 @@ class TestFakeIO:
"""Test FakeIO.""" """Test FakeIO."""
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def restore_streams(self): def restore_streams(self):
"""Restore sys.stderr/sys.stdout after tests.""" """Restore sys.stderr/sys.stdout after tests."""
old_stdout = sys.stdout old_stdout = sys.stdout
@ -682,7 +682,7 @@ class TestDisabledExcepthook:
the excepthook (which is hard to test). the excepthook (which is hard to test).
""" """
@pytest.yield_fixture(autouse=True) @pytest.fixture(autouse=True)
def restore_excepthook(self): def restore_excepthook(self):
"""Restore sys.excepthook and sys.__excepthook__ after tests.""" """Restore sys.excepthook and sys.__excepthook__ after tests."""
old_excepthook = sys.excepthook old_excepthook = sys.excepthook

View File

@ -74,7 +74,7 @@ class TestGitStr:
"""Tests for _git_str().""" """Tests for _git_str()."""
@pytest.yield_fixture @pytest.fixture
def commit_file_mock(self, mocker): def commit_file_mock(self, mocker):
"""Fixture providing a mock for utils.read_file for git-commit-id. """Fixture providing a mock for utils.read_file for git-commit-id.