Merge branch 'pytest30'
This commit is contained in:
commit
64a61ce07f
4
.flake8
4
.flake8
@ -6,6 +6,8 @@ exclude = .*,__pycache__,resources.py
|
||||
# E501: Line too long
|
||||
# E402: module level import not at top of file
|
||||
# E266: too many leading '#' for block comment
|
||||
# E731: do not assign a lambda expression, use a def
|
||||
# (for pytest's __tracebackhide__)
|
||||
# F401: Unused import
|
||||
# N802: function name should be lowercase
|
||||
# P101: format string does contain unindexed parameters
|
||||
@ -27,7 +29,7 @@ exclude = .*,__pycache__,resources.py
|
||||
# H301: one import per line
|
||||
# H306: imports not in alphabetical order
|
||||
ignore =
|
||||
E128,E226,E265,E501,E402,E266,
|
||||
E128,E226,E265,E501,E402,E266,E731,
|
||||
F401,
|
||||
N802,
|
||||
P101,P102,P103,
|
||||
|
@ -68,6 +68,8 @@ max-args=10
|
||||
valid-metaclass-classmethod-first-arg=cls
|
||||
|
||||
[TYPECHECK]
|
||||
# WORKAROUND for https://github.com/PyCQA/astroid/pull/357
|
||||
ignored-modules=pytest
|
||||
# MsgType added as WORKAROUND for
|
||||
# https://bitbucket.org/logilab/pylint/issues/690/
|
||||
# UnsetObject because pylint infers any objreg.get(...) as UnsetObject.
|
||||
|
@ -16,8 +16,8 @@ Mako==1.0.4
|
||||
parse==1.6.6
|
||||
parse-type==0.3.4
|
||||
py==1.4.31
|
||||
pytest==2.9.2
|
||||
pytest-bdd==2.17.0
|
||||
pytest==3.0.0
|
||||
pytest-bdd==2.17.1
|
||||
pytest-catchlog==1.2.2
|
||||
pytest-cov==2.3.1
|
||||
pytest-faulthandler==1.3.0
|
||||
|
@ -272,14 +272,14 @@ def main_check_all():
|
||||
This makes sure the files have 100% coverage without running unrelated
|
||||
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.
|
||||
"""
|
||||
for test_file, src_file in PERFECT_FILES:
|
||||
if test_file is None:
|
||||
continue
|
||||
subprocess.check_call(
|
||||
[sys.executable, '-m', 'py.test', '--cov', 'qutebrowser',
|
||||
[sys.executable, '-m', 'pytest', '--cov', 'qutebrowser',
|
||||
'--cov-report', 'xml', test_file])
|
||||
with open('coverage.xml', encoding='utf-8') as f:
|
||||
messages = check(f, [(test_file, src_file)])
|
||||
|
@ -53,7 +53,7 @@ def temp_git_commit_file():
|
||||
def get_build_exe_options():
|
||||
"""Get build_exe options with additional includes."""
|
||||
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',
|
||||
'httpbin', 'jinja2.ext', 'cherrypy.wsgiserver',
|
||||
'pstats']
|
||||
|
@ -86,8 +86,8 @@ def pytest_collection_modifyitems(items):
|
||||
|
||||
For example:
|
||||
|
||||
py.test -m "not gui" # run all tests except gui tests
|
||||
py.test -m "gui" # run only gui tests
|
||||
pytest -m "not gui" # run all tests except gui tests
|
||||
pytest -m "gui" # run only gui tests
|
||||
|
||||
It also handles the platform specific markers by translating them to skipif
|
||||
markers.
|
||||
@ -133,6 +133,12 @@ def qapp(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):
|
||||
parser.addoption('--qute-delay', action='store', default=0, type=int,
|
||||
help="Delay between qutebrowser commands.")
|
||||
|
@ -430,9 +430,7 @@ def compare_session(request, quteproc, expected):
|
||||
compared.
|
||||
"""
|
||||
if request.config.getoption('--qute-bdd-webengine'):
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
|
||||
# pylint: enable=no-member
|
||||
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.
|
||||
"""
|
||||
if request.config.getoption('--qute-bdd-webengine'):
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
|
||||
# pylint: enable=no-member
|
||||
session = quteproc.get_session()
|
||||
active_suffix = ' (active)'
|
||||
tabs = tabs.splitlines()
|
||||
@ -556,9 +552,7 @@ def _get_scroll_values(quteproc):
|
||||
r"(?P<direction>horizontally|vertically)"))
|
||||
def check_scrolled(request, quteproc, direction):
|
||||
if request.config.getoption('--qute-bdd-webengine'):
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
|
||||
# pylint: enable=no-member
|
||||
x, y = _get_scroll_values(quteproc)
|
||||
if direction == 'horizontally':
|
||||
assert x != 0
|
||||
@ -571,9 +565,7 @@ def check_scrolled(request, quteproc, direction):
|
||||
@bdd.then("the page should not be scrolled")
|
||||
def check_not_scrolled(request, quteproc):
|
||||
if request.config.getoption('--qute-bdd-webengine'):
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
|
||||
# pylint: enable=no-member
|
||||
x, y = _get_scroll_values(quteproc)
|
||||
assert x == 0
|
||||
assert y == 0
|
||||
|
@ -25,9 +25,7 @@ bdd.scenarios('marks.feature')
|
||||
@bdd.then(bdd.parsers.parse("the page should be scrolled to {x} {y}"))
|
||||
def check_y(request, quteproc, x, y):
|
||||
if request.config.getoption('--qute-bdd-webengine'):
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
|
||||
# pylint: enable=no-member
|
||||
data = quteproc.get_session()
|
||||
pos = data['windows'][0]['tabs'][0]['history'][-1]['scroll-pos']
|
||||
assert int(x) == pos['x']
|
||||
|
@ -46,9 +46,6 @@ instance_counter = itertools.count()
|
||||
|
||||
def is_ignored_qt_message(message):
|
||||
"""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')
|
||||
for regex in regexes:
|
||||
if re.match(regex, message):
|
||||
@ -277,7 +274,7 @@ class QuteProc(testprocess.Process):
|
||||
if path.startswith('about:') or path.startswith('qute:'):
|
||||
return path
|
||||
else:
|
||||
httpbin = self.request.getfuncargvalue('httpbin')
|
||||
httpbin = self.request.getfixturevalue('httpbin')
|
||||
return '{}://localhost:{}/{}'.format(
|
||||
'https' if https else 'http',
|
||||
httpbin.port if port is None else port,
|
||||
@ -295,6 +292,8 @@ class QuteProc(testprocess.Process):
|
||||
|
||||
def wait_for(self, timeout=None, **kwargs):
|
||||
"""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')
|
||||
if xfail and xfail.args[0]:
|
||||
kwargs['divisor'] = 10
|
||||
@ -347,7 +346,7 @@ class QuteProc(testprocess.Process):
|
||||
|
||||
def after_test(self):
|
||||
"""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
|
||||
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,
|
||||
load_status='success'):
|
||||
"""Wait until a URL has finished loading."""
|
||||
__tracebackhide__ = True
|
||||
__tracebackhide__ = (lambda e: e.errisinstance(
|
||||
testprocess.WaitForTimeout))
|
||||
|
||||
if timeout is None:
|
||||
if 'CI' in os.environ:
|
||||
@ -496,7 +496,8 @@ class QuteProc(testprocess.Process):
|
||||
def wait_for_load_finished(self, path, *, port=None, https=False,
|
||||
timeout=None, load_status='success'):
|
||||
"""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)
|
||||
self.wait_for_load_finished_url(url, timeout=timeout,
|
||||
load_status=load_status)
|
||||
@ -562,7 +563,7 @@ class QuteProc(testprocess.Process):
|
||||
partial_compare is used, which means only the keys/values listed will
|
||||
be compared.
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
__tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception)
|
||||
# Translate ... to ellipsis in YAML.
|
||||
loader = yaml.SafeLoader(expected)
|
||||
loader.add_constructor('!ellipsis', lambda loader, node: ...)
|
||||
@ -606,7 +607,7 @@ def _xpath_escape(text):
|
||||
return 'concat({})'.format(', '.join(parts))
|
||||
|
||||
|
||||
@pytest.yield_fixture(scope='module')
|
||||
@pytest.fixture(scope='module')
|
||||
def quteproc_process(qapp, httpbin, request):
|
||||
"""Fixture for qutebrowser process which is started once per file."""
|
||||
# Passing request so it has an initial config
|
||||
@ -616,7 +617,7 @@ def quteproc_process(qapp, httpbin, request):
|
||||
proc.terminate()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def quteproc(quteproc_process, httpbin, request):
|
||||
"""Per-test qutebrowser fixture which uses the per-file process."""
|
||||
request.node._quteproc_log = quteproc_process.captured_log
|
||||
@ -626,7 +627,7 @@ def quteproc(quteproc_process, httpbin, request):
|
||||
quteproc_process.after_test()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def quteproc_new(qapp, httpbin, request):
|
||||
"""Per-test qutebrowser process to test invocations."""
|
||||
proc = QuteProc(request)
|
||||
|
@ -70,7 +70,7 @@ class FakeRequest:
|
||||
self.config = config
|
||||
self._httpbin = httpbin
|
||||
|
||||
def getfuncargvalue(self, name):
|
||||
def getfixturevalue(self, name):
|
||||
assert name == 'httpbin'
|
||||
return self._httpbin
|
||||
|
||||
|
@ -102,21 +102,21 @@ class NoReadyPythonProcess(PythonProcess):
|
||||
return (sys.executable, ['-c', ';'.join(code)])
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def pyproc():
|
||||
proc = PythonProcess()
|
||||
yield proc
|
||||
proc.terminate()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def quit_pyproc():
|
||||
proc = QuitPythonProcess()
|
||||
yield proc
|
||||
proc.terminate()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def noready_pyproc():
|
||||
proc = NoReadyPythonProcess()
|
||||
yield proc
|
||||
|
@ -77,7 +77,6 @@ class Line:
|
||||
|
||||
def _render_log(data, threshold=100):
|
||||
"""Shorten the given log without -v and convert to a string."""
|
||||
# pylint: disable=no-member
|
||||
data = [str(d) for d in data]
|
||||
is_exception = any('Traceback (most recent call last):' in line
|
||||
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.
|
||||
return
|
||||
|
||||
# pylint: disable=no-member
|
||||
if pytest.config.getoption('--capture') == 'no':
|
||||
# Already printed live
|
||||
return
|
||||
@ -153,7 +151,6 @@ class Process(QObject):
|
||||
|
||||
def _log(self, line):
|
||||
"""Add the given line to the captured log output."""
|
||||
# pylint: disable=no-member
|
||||
if pytest.config.getoption('--capture') == 'no':
|
||||
print(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
|
||||
unexpected output lines earlier.
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
__tracebackhide__ = lambda e: e.errisinstance(ProcessExited)
|
||||
self.captured_log = []
|
||||
if self._invalid:
|
||||
# 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.
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
for line in self._data:
|
||||
matches = []
|
||||
|
||||
@ -362,7 +358,7 @@ class Process(QObject):
|
||||
|
||||
Called via wait_for.
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
__tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
|
||||
message = kwargs.get('message', None)
|
||||
if message is not None:
|
||||
elided = quteutils.elide(repr(message), 50)
|
||||
@ -441,7 +437,7 @@ class Process(QObject):
|
||||
Return:
|
||||
The matched line.
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
__tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
|
||||
|
||||
if timeout is None:
|
||||
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
|
||||
nothing arrives.
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
__tracebackhide__ = lambda e: e.errisinstance(BlacklistedMessageError)
|
||||
try:
|
||||
line = self.wait_for(timeout=delay, override_waited_for=True,
|
||||
**kwargs)
|
||||
|
@ -167,7 +167,7 @@ class WebserverProcess(testprocess.Process):
|
||||
self.proc.waitForFinished()
|
||||
|
||||
|
||||
@pytest.yield_fixture(scope='session', autouse=True)
|
||||
@pytest.fixture(scope='session', autouse=True)
|
||||
def httpbin(qapp):
|
||||
"""Fixture for an httpbin object which ensures clean setup/teardown."""
|
||||
httpbin = WebserverProcess('webserver_sub')
|
||||
@ -176,7 +176,7 @@ def httpbin(qapp):
|
||||
httpbin.cleanup()
|
||||
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def httpbin_after_test(httpbin, request):
|
||||
"""Fixture to clean httpbin request list after each test."""
|
||||
request.node._httpbin_log = httpbin.captured_log
|
||||
@ -184,7 +184,7 @@ def httpbin_after_test(httpbin, request):
|
||||
httpbin.after_test()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def ssl_server(request, qapp):
|
||||
"""Fixture for a webserver with a self-signed SSL certificate.
|
||||
|
||||
|
@ -54,8 +54,6 @@ def turn_off_logging():
|
||||
def main():
|
||||
ssl_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
||||
'..', '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.load_cert_chain(os.path.join(ssl_dir, 'cert.pem'),
|
||||
os.path.join(ssl_dir, 'key.pem'))
|
||||
|
@ -93,9 +93,7 @@ def test_hints(test_name, zoom_text_only, zoom_level, find_implementation,
|
||||
|
||||
parsed = _parse_file(test_name)
|
||||
if parsed.qtwebengine_todo is not None and webengine:
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail("QtWebEngine TODO: {}".format(parsed.qtwebengine_todo))
|
||||
# pylint: enable=no-member
|
||||
|
||||
url_path = 'data/hints/html/{}'.format(test_name)
|
||||
quteproc.open_path(url_path)
|
||||
|
@ -49,10 +49,8 @@ def test_insert_mode(file_name, elem_id, source, input_text, auto_insert,
|
||||
quteproc.press_keys(input_text)
|
||||
elif source == 'clipboard':
|
||||
if request.config.getoption('--qute-bdd-webengine'):
|
||||
# pylint: disable=no-member
|
||||
pytest.xfail(reason="QtWebEngine TODO: :insert-text is not "
|
||||
"implemented")
|
||||
# pylint: enable=no-member
|
||||
quteproc.send_cmd(':debug-set-fake-clipboard "{}"'.format(input_text))
|
||||
quteproc.send_cmd(':insert-text {clipboard}')
|
||||
|
||||
|
@ -41,7 +41,6 @@ def test_smoke(cmd, capfd):
|
||||
if e.returncode == -signal.SIGSEGV:
|
||||
_out, err = capfd.readouterr()
|
||||
assert 'Uncaught exception' not in err
|
||||
# pylint: disable=no-member
|
||||
# https://github.com/The-Compiler/qutebrowser/issues/1387
|
||||
pytest.xfail("Ignoring segfault on exit...")
|
||||
else:
|
||||
|
@ -137,7 +137,7 @@ def fake_statusbar(qtbot):
|
||||
return statusbar
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def win_registry():
|
||||
"""Fixture providing a window registry for win_id 0 and 1."""
|
||||
helper = WinRegistryHelper()
|
||||
@ -146,7 +146,7 @@ def win_registry():
|
||||
helper.cleanup()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def tab_registry(win_registry):
|
||||
"""Fixture providing a tab registry for win_id 0."""
|
||||
registry = objreg.ObjectRegistry()
|
||||
@ -203,7 +203,7 @@ def cmdline_test(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def config_stub(stubs):
|
||||
"""Fixture which provides a fake config object."""
|
||||
stub = stubs.ConfigStub()
|
||||
@ -212,7 +212,7 @@ def config_stub(stubs):
|
||||
objreg.delete('config')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def default_config():
|
||||
"""Fixture that provides and registers an empty default config object."""
|
||||
config_obj = config.ConfigManager()
|
||||
@ -222,7 +222,7 @@ def default_config():
|
||||
objreg.delete('config')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def key_config_stub(stubs):
|
||||
"""Fixture which provides a fake key config object."""
|
||||
stub = stubs.KeyConfigStub()
|
||||
@ -231,7 +231,7 @@ def key_config_stub(stubs):
|
||||
objreg.delete('key-config')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def host_blocker_stub(stubs):
|
||||
"""Fixture which provides a fake host blocker object."""
|
||||
stub = stubs.HostBlockerStub()
|
||||
@ -240,7 +240,7 @@ def host_blocker_stub(stubs):
|
||||
objreg.delete('host-blocker')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def quickmark_manager_stub(stubs):
|
||||
"""Fixture which provides a fake quickmark manager object."""
|
||||
stub = stubs.QuickmarkManagerStub()
|
||||
@ -249,7 +249,7 @@ def quickmark_manager_stub(stubs):
|
||||
objreg.delete('quickmark-manager')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def bookmark_manager_stub(stubs):
|
||||
"""Fixture which provides a fake bookmark manager object."""
|
||||
stub = stubs.BookmarkManagerStub()
|
||||
@ -258,7 +258,7 @@ def bookmark_manager_stub(stubs):
|
||||
objreg.delete('bookmark-manager')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def web_history_stub(stubs):
|
||||
"""Fixture which provides a fake web-history object."""
|
||||
stub = stubs.WebHistoryStub()
|
||||
@ -267,7 +267,7 @@ def web_history_stub(stubs):
|
||||
objreg.delete('web-history')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def session_manager_stub(stubs):
|
||||
"""Fixture which provides a fake web-history object."""
|
||||
stub = stubs.SessionManagerStub()
|
||||
@ -276,7 +276,7 @@ def session_manager_stub(stubs):
|
||||
objreg.delete('session-manager')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def tabbed_browser_stubs(stubs, win_registry):
|
||||
"""Fixture providing a fake tabbed-browser object on win_id 0 and 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)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def app_stub(stubs):
|
||||
"""Fixture which provides a fake app object."""
|
||||
stub = stubs.ApplicationStub()
|
||||
@ -297,7 +297,7 @@ def app_stub(stubs):
|
||||
objreg.delete('app')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def status_command_stub(stubs, qtbot, win_registry):
|
||||
"""Fixture which provides a fake status-command object."""
|
||||
cmd = stubs.StatusBarCommandStub()
|
||||
@ -387,7 +387,7 @@ def fake_keyevent_factory():
|
||||
return fake_keyevent
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def cookiejar_and_cache(stubs):
|
||||
"""Fixture providing a fake cookie jar and cache."""
|
||||
jar = QNetworkCookieJar()
|
||||
@ -414,7 +414,7 @@ def py_proc():
|
||||
return func
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def fake_save_manager():
|
||||
"""Create a mock of save-manager and register it into objreg."""
|
||||
fake_save_manager = unittest.mock.Mock(spec=savemanager.SaveManager)
|
||||
@ -423,7 +423,7 @@ def fake_save_manager():
|
||||
objreg.delete('save-manager')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def fake_args():
|
||||
ns = types.SimpleNamespace()
|
||||
objreg.register('args', ns)
|
||||
@ -431,7 +431,7 @@ def fake_args():
|
||||
objreg.delete('args')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def mode_manager(win_registry, config_stub, qapp):
|
||||
config_stub.data.update({'input': {'forward-unbound-keys': 'auto'}})
|
||||
mm = modeman.ModeManager(0)
|
||||
|
@ -70,7 +70,7 @@ class LogFailHandler(logging.Handler):
|
||||
record.getMessage()))
|
||||
|
||||
|
||||
@pytest.yield_fixture(scope='session', autouse=True)
|
||||
@pytest.fixture(scope='session', autouse=True)
|
||||
def fail_on_logging():
|
||||
handler = LogFailHandler()
|
||||
logging.getLogger().addHandler(handler)
|
||||
|
@ -45,6 +45,7 @@ def test_partial_compare_equal(val1, val2):
|
||||
({1: 1}, {1: [1]}, "Different types (int, list) -> False"),
|
||||
({'a': [1, 2, 3]}, {'a': [..., 3]}, "2 != 3"),
|
||||
("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):
|
||||
outcome = utils.partial_compare(val1, val2)
|
||||
|
@ -26,6 +26,8 @@ import re
|
||||
import pprint
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class PartialCompareOutcome:
|
||||
|
||||
@ -84,7 +86,7 @@ def _partial_compare_list(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("{!r} != {!r} (float comparison)".format(
|
||||
|
@ -96,7 +96,7 @@ class FakeDownloadManager:
|
||||
return download_item
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def download_stub(win_registry):
|
||||
"""Register a FakeDownloadManager."""
|
||||
stub = FakeDownloadManager()
|
||||
|
@ -32,7 +32,7 @@ ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd'])
|
||||
pytestmark = pytest.mark.usefixtures('cookiejar_and_cache')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def objects(qtbot, default_config, key_config_stub, tab_registry,
|
||||
host_blocker_stub):
|
||||
"""Fixture providing a CommandDispatcher and a fake TabbedBrowser."""
|
||||
|
@ -83,7 +83,7 @@ def objects():
|
||||
return Objects(signal_filter=signal_filter, signaller=signaller)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def tabbed_browser(win_registry):
|
||||
tb = FakeTabbedBrowser()
|
||||
objreg.register('tabbed-browser', tb, scope='window', window=0)
|
||||
|
@ -58,7 +58,7 @@ def view(qtbot, config_stub, request):
|
||||
return v
|
||||
|
||||
|
||||
@pytest.yield_fixture(params=['webkit', 'webengine'])
|
||||
@pytest.fixture(params=['webkit', 'webengine'])
|
||||
def tab(request, default_config, qtbot, tab_registry, cookiejar_and_cache):
|
||||
if PYQT_VERSION < 0x050600:
|
||||
pytest.skip('Causes segfaults, see #1638')
|
||||
|
@ -366,7 +366,7 @@ def test_entry_str(entry, expected):
|
||||
assert str(entry) == expected
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def hist_interface():
|
||||
entry = history.Entry(atime=0, url=QUrl('http://www.example.com/'),
|
||||
title='example')
|
||||
|
@ -46,7 +46,7 @@ class TestArgumentParser:
|
||||
def parser(self):
|
||||
return argparser.ArgumentParser('foo')
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def tabbed_browser(self, win_registry):
|
||||
tb = FakeTabbedBrowser()
|
||||
objreg.register('tabbed-browser', tb, scope='window', window=0)
|
||||
|
@ -38,7 +38,7 @@ def guiprocess_message_mock(message_mock):
|
||||
@pytest.mark.posix
|
||||
class TestQtFIFOReader:
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def reader(self, tmpdir, qapp):
|
||||
fifo_path = str(tmpdir / 'fifo')
|
||||
os.mkfifo(fifo_path) # pylint: disable=no-member,useless-suppression
|
||||
|
@ -411,7 +411,7 @@ class TestConfigInit:
|
||||
|
||||
"""Test initializing of the config."""
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch(self, fake_args):
|
||||
objreg.register('app', QObject())
|
||||
objreg.register('save-manager', mock.MagicMock())
|
||||
|
@ -26,7 +26,7 @@ from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtWebKitWidgets import QWebPage
|
||||
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def enable_caret_browsing(qapp):
|
||||
"""Fixture to enable caret browsing globally."""
|
||||
settings = QWebSettings.globalSettings()
|
||||
|
@ -35,7 +35,7 @@ BINDINGS = {'test': {'<Ctrl-a>': 'ctrla',
|
||||
'normal': {'a': 'a', 'ba': 'ba'}}
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def fake_keyconfig():
|
||||
"""Create a mock of a KeyConfiguration and register it into objreg."""
|
||||
bindings = dict(BINDINGS) # so the bindings can be changed later
|
||||
|
@ -33,7 +33,7 @@ from qutebrowser.utils import utils
|
||||
CONFIG = {'input': {'timeout': 100}}
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def keyparser():
|
||||
"""Fixture providing a BaseKeyParser supporting count/chains."""
|
||||
kp = basekeyparser.BaseKeyParser(
|
||||
|
@ -27,7 +27,7 @@ from qutebrowser.mainwindow.statusbar.prompt import Prompt
|
||||
from qutebrowser.utils import objreg
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def prompt(qtbot, win_registry):
|
||||
prompt = Prompt(0)
|
||||
qtbot.addWidget(prompt)
|
||||
|
@ -41,7 +41,7 @@ def patch_things(config_stub, message_mock, monkeypatch, stubs):
|
||||
monkeypatch.setattr('qutebrowser.misc.editor.config', config_stub)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def editor():
|
||||
ed = editormod.ExternalEditor(0)
|
||||
ed.editing_finished = mock.Mock()
|
||||
|
@ -34,7 +34,7 @@ def guiprocess_message_mock(message_mock):
|
||||
return message_mock
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
@pytest.fixture()
|
||||
def proc(qtbot):
|
||||
"""A fixture providing a GUIProcess and cleaning it up after the test."""
|
||||
p = guiprocess.GUIProcess(0, 'testprocess')
|
||||
|
@ -45,13 +45,13 @@ from helpers import stubs
|
||||
pytestmark = pytest.mark.usefixtures('qapp')
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
@pytest.fixture()
|
||||
def short_tmpdir():
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
yield py.path.local(tdir) # pylint: disable=no-member
|
||||
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def shutdown_server():
|
||||
"""If ipc.send_or_listen was called, make sure to shut server down."""
|
||||
yield
|
||||
@ -63,7 +63,7 @@ def shutdown_server():
|
||||
server.shutdown()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def ipc_server(qapp, qtbot):
|
||||
server = ipc.IPCServer('qute-test')
|
||||
yield server
|
||||
@ -77,7 +77,7 @@ def ipc_server(qapp, qtbot):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def qlocalserver(qapp):
|
||||
server = QLocalServer()
|
||||
yield server
|
||||
@ -85,7 +85,7 @@ def qlocalserver(qapp):
|
||||
server.deleteLater()
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def qlocalsocket(qapp):
|
||||
socket = QLocalSocket()
|
||||
yield socket
|
||||
@ -447,7 +447,7 @@ class TestHandleConnection:
|
||||
assert "We can read a line immediately." in all_msgs
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def connected_socket(qtbot, qlocalsocket, ipc_server):
|
||||
if sys.platform == 'darwin':
|
||||
pytest.skip("Skipping connected_socket test - "
|
||||
@ -654,7 +654,7 @@ class TestSendOrListen:
|
||||
setattr(m, attr, getattr(QLocalSocket, attr))
|
||||
return m
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def legacy_server(self, args):
|
||||
legacy_name = ipc._get_socketname(args.basedir, legacy=True)
|
||||
legacy_server = ipc.IPCServer(legacy_name)
|
||||
|
@ -31,7 +31,7 @@ class TestCommandLineEdit:
|
||||
|
||||
"""Tests for CommandLineEdit widget."""
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def cmd_edit(self, qtbot):
|
||||
"""Fixture to initialize a CommandLineEdit."""
|
||||
cmd_edit = miscwidgets.CommandLineEdit(None)
|
||||
|
@ -50,7 +50,7 @@ def sess_man():
|
||||
|
||||
class TestInit:
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup(self):
|
||||
yield
|
||||
objreg.delete('session-manager')
|
||||
@ -313,7 +313,7 @@ class FakeTabbedBrowser:
|
||||
return 1
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def fake_windows(win_registry, stubs, monkeypatch, qtbot):
|
||||
"""Fixture which provides two fake main windows and tabbedbrowsers."""
|
||||
win_registry.add_window(1)
|
||||
@ -400,14 +400,14 @@ def test_get_session_name(config_stub, sess_man, arg, config, current,
|
||||
|
||||
class TestSave:
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def state_config(self):
|
||||
state = {'general': {}}
|
||||
objreg.register('state-config', state)
|
||||
yield state
|
||||
objreg.delete('state-config')
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def fake_history(self, win_registry, stubs, monkeypatch, webview):
|
||||
"""Fixture which provides a window with a fake history."""
|
||||
win = FakeMainWindow(b'fake-geometry-0', win_id=0)
|
||||
|
@ -32,7 +32,7 @@ from qutebrowser.utils import log
|
||||
from qutebrowser.misc import utilcmds
|
||||
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_loggers():
|
||||
"""Fixture to save/restore the logging state.
|
||||
|
||||
|
@ -375,7 +375,7 @@ class TestSavefileOpen:
|
||||
|
||||
## Tests with a mock testing that the needed methods are called.
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def qsavefile_mock(self, mocker):
|
||||
"""Mock for 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.
|
||||
|
||||
@pytest.yield_fixture(scope='session', autouse=True)
|
||||
@pytest.fixture(scope='session', autouse=True)
|
||||
def clean_up_python_testfile():
|
||||
"""Clean up the python testfile after tests if tests didn't."""
|
||||
yield
|
||||
@ -641,7 +641,7 @@ class TestPyQIODevice:
|
||||
|
||||
"""Tests for PyQIODevice."""
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def pyqiodev(self):
|
||||
"""Fixture providing a PyQIODevice with a QByteArray to test."""
|
||||
data = QByteArray()
|
||||
|
@ -32,7 +32,7 @@ import pytest
|
||||
from qutebrowser.utils import standarddir
|
||||
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def change_qapp_name(qapp):
|
||||
"""Change the name of the QApplication instance.
|
||||
|
||||
@ -52,7 +52,7 @@ def no_cachedir_tag(monkeypatch):
|
||||
lambda: None)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def reset_standarddir(no_cachedir_tag):
|
||||
"""Clean up standarddir arguments before and after each test."""
|
||||
standarddir.init(None)
|
||||
|
@ -589,7 +589,7 @@ class TestFakeIO:
|
||||
|
||||
"""Test FakeIO."""
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_streams(self):
|
||||
"""Restore sys.stderr/sys.stdout after tests."""
|
||||
old_stdout = sys.stdout
|
||||
@ -682,7 +682,7 @@ class TestDisabledExcepthook:
|
||||
the excepthook (which is hard to test).
|
||||
"""
|
||||
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_excepthook(self):
|
||||
"""Restore sys.excepthook and sys.__excepthook__ after tests."""
|
||||
old_excepthook = sys.excepthook
|
||||
|
@ -74,7 +74,7 @@ class TestGitStr:
|
||||
|
||||
"""Tests for _git_str()."""
|
||||
|
||||
@pytest.yield_fixture
|
||||
@pytest.fixture
|
||||
def commit_file_mock(self, mocker):
|
||||
"""Fixture providing a mock for utils.read_file for git-commit-id.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user