diff --git a/fix_catch_log_handler.patch b/fix_catch_log_handler.patch new file mode 100644 index 0000000..b0d46b5 --- /dev/null +++ b/fix_catch_log_handler.patch @@ -0,0 +1,113 @@ +From 0070eddfc33fc2fba8eb4fe9353a2d2fa1ae575b Mon Sep 17 00:00:00 2001 +From: Nikolaus Rath +Date: Sat, 21 Nov 2020 11:39:46 +0000 +Subject: [PATCH] Use fixtures instead of hooks for inspecting output. + +This should make us less dependent on pytest internals and compatible +with pytest 6. + +Fixes: #27. +--- + setup.py | 2 - + test/pytest_checklogs.py | 54 +++++++++++++---------------------------------- + 2 files changed, 16 insertions(+), 40 deletions(-) + +--- a/setup.py ++++ b/setup.py +@@ -136,7 +136,7 @@ def main(): + platforms=[ 'Linux' ], + keywords=['FUSE', 'python' ], + install_requires=['trio'], +- tests_require=['pytest', 'pytest-trio'], ++ tests_require=['pytest >= 3.4.0', 'pytest-trio'], + python_requires='>=3.5', + package_dir={'': 'src'}, + py_modules=['_pyfuse3', 'pyfuse3_asyncio'], +--- a/test/pytest_checklogs.py ++++ b/test/pytest_checklogs.py +@@ -19,20 +19,7 @@ import functools + import sys + import logging + from contextlib import contextmanager +-from distutils.version import LooseVersion + +-def pytest_configure(config): +- # pytest-catchlog was integrated in pytest 3.3.0 +- if (LooseVersion(pytest.__version__) < "3.3.0" and +- not config.pluginmanager.hasplugin('pytest_catchlog')): +- raise ImportError('pytest catchlog plugin not found') +- +-# Fail tests if they result in log messages of severity WARNING or more. +-def check_test_log(caplog): +- for record in caplog.records: +- if (record.levelno >= logging.WARNING and +- not getattr(record, 'checklogs_ignore', False)): +- raise AssertionError('Logger received warning messages') + + class CountMessagesHandler(logging.Handler): + def __init__(self, level=logging.NOTSET): +@@ -75,16 +62,12 @@ def assert_logs(pattern, level=logging.W + logger.removeHandler(handler) + + if count is not None and handler.count != count: +- raise AssertionError('Expected to catch %d %r messages, but got only %d' +- % (count, pattern, handler.count)) ++ pytest.fail('Expected to catch %d %r messages, but got only %d' ++ % (count, pattern, handler.count)) + + def check_test_output(capfd, item): + (stdout, stderr) = capfd.readouterr() + +- # Write back what we've read (so that it will still be printed) +- sys.stdout.write(stdout) +- sys.stderr.write(stderr) +- + # Strip out false positives + try: + false_pos = item.checklogs_fp +@@ -101,10 +84,10 @@ def check_test_output(capfd, item): + cp = re.compile(r'\b{}\b'.format(pattern), re.IGNORECASE | re.MULTILINE) + hit = cp.search(stderr) + if hit: +- raise AssertionError('Suspicious output to stderr (matched "%s")' % hit.group(0)) ++ pytest.fail('Suspicious output to stderr (matched "%s")' % hit.group(0)) + hit = cp.search(stdout) + if hit: +- raise AssertionError('Suspicious output to stdout (matched "%s")' % hit.group(0)) ++ pytest.fail('Suspicious output to stdout (matched "%s")' % hit.group(0)) + + def register_output(item, pattern, count=1, flags=re.MULTILINE): + '''Register *pattern* as false positive for output checking +@@ -121,21 +104,14 @@ def reg_output(request): + request.node.checklogs_fp = [] + return functools.partial(register_output, request.node) + +-def check_output(item): +- pm = item.config.pluginmanager +- cm = pm.getplugin('capturemanager') +- capmethod = (getattr(cm, '_capturing', None) or +- getattr(item, '_capture_fixture', None) or +- getattr(cm, '_global_capturing', None)) +- check_test_output(capmethod, item) +- check_test_log(item.catch_log_handler) +- +-@pytest.hookimpl(trylast=True) +-def pytest_runtest_setup(item): +- check_output(item) +-@pytest.hookimpl(trylast=True) +-def pytest_runtest_call(item): +- check_output(item) +-@pytest.hookimpl(trylast=True) +-def pytest_runtest_teardown(item, nextitem): +- check_output(item) ++# Autouse fixtures are instantiated before explicitly used fixtures, this should also ++# catch log messages emitted when e.g. initializing resources in other fixtures. ++@pytest.fixture(autouse=True) ++def check_output(caplog, capfd, request): ++ yield ++ for when in ("setup", "call", "teardown"): ++ for record in caplog.get_records(when): ++ if (record.levelno >= logging.WARNING and ++ not getattr(record, 'checklogs_ignore', False)): ++ pytest.fail('Logger received warning messages.') ++ check_test_output(capfd, request) diff --git a/python-pyfuse3.changes b/python-pyfuse3.changes index 2888d8c..503d732 100644 --- a/python-pyfuse3.changes +++ b/python-pyfuse3.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Mon Mar 15 18:11:55 UTC 2021 - Matej Cepl + +- Add fix_catch_log_handler.patch to make tests compatible with + pytest >= 6.0.0, which removed never documented attribute + .catch_log_handler of log item (gh#libfuse/pyfuse3#27). + ------------------------------------------------------------------- Fri Aug 7 15:46:22 UTC 2020 - Marketa Calabkova diff --git a/python-pyfuse3.spec b/python-pyfuse3.spec index cf08bf1..edc5ac7 100644 --- a/python-pyfuse3.spec +++ b/python-pyfuse3.spec @@ -1,7 +1,7 @@ # # spec file for package python-pyfuse3 # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -26,10 +26,13 @@ Summary: Python Bindings for the low-level FUSE3 API License: LGPL-2.1-or-later URL: https://github.com/libfuse/pyfuse3 Source: https://github.com/libfuse/pyfuse3/archive/release-%{version}.tar.gz#/%{pname}-%{version}.tar.gz +# PATCH-FIX-UPSTREAM fix_catch_log_handler.patch gh#libfuse/pyfuse3#27 mcepl@suse.com +# works around the removed attribute of log handlers .catch_log_handler +Patch0: fix_catch_log_handler.patch BuildRequires: %{python_module Cython} BuildRequires: %{python_module devel} +BuildRequires: %{python_module pytest >= 3.4.0} BuildRequires: %{python_module pytest-trio} -BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} BuildRequires: %{python_module trio} BuildRequires: fdupes @@ -44,7 +47,7 @@ Recommends: fuse3 >= 3.3.0 pyfuse3 is a set of Python 3 bindings for libfuse 3. It provides an asynchronous API compatible with Trio and asyncio, and enables you to easily write a full-featured Linux filesystem in Python. %prep -%setup -q -n %{pname}-release-%{version} +%autosetup -p1 -n %{pname}-release-%{version} %build %python_expand $python setup.py build_cython