commit python-pytest-timeout for openSUSE:Factory
Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-pytest-timeout for openSUSE:Factory checked in at 2022-08-30 14:48:28 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pytest-timeout (Old) and /work/SRC/openSUSE:Factory/.python-pytest-timeout.new.2083 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-pytest-timeout" Tue Aug 30 14:48:28 2022 rev:12 rq:999928 version:2.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pytest-timeout/python-pytest-timeout.changes 2022-01-07 12:46:02.235831126 +0100 +++ /work/SRC/openSUSE:Factory/.python-pytest-timeout.new.2083/python-pytest-timeout.changes 2022-08-30 14:48:33.767980000 +0200 @@ -1,0 +2,10 @@ +Fri Aug 19 18:22:49 UTC 2022 - Ben Greiner <code@bnavigator.de> + +- Update to 2.1.0 + * Get terminal width from shutil instead of deprecated py, thanks + Andrew Svetlov. + * Add an API for extending ``pytest-timeout`` functionality + with third-party plugins, thanks Andrew Svetlov. +- Don't test with pytest-cov in Staging: Put Ring1 on coverage diet + +------------------------------------------------------------------- Old: ---- pytest-timeout-2.0.2.tar.gz New: ---- pytest-timeout-2.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pytest-timeout.spec ++++++ --- /var/tmp/diff_new_pack.WEvclO/_old 2022-08-30 14:48:34.291981337 +0200 +++ /var/tmp/diff_new_pack.WEvclO/_new 2022-08-30 14:48:34.295981346 +0200 @@ -16,22 +16,27 @@ # -%{?!python_module:%define python_module() python-%{**} python3-%{**}} +%{?!python_module:%define python_module() python3-%{**}} %define skip_python2 1 +%bcond_with ringdisabled Name: python-pytest-timeout -Version: 2.0.2 +Version: 2.1.0 Release: 0 Summary: Pytest plugin to abort hanging tests License: MIT URL: https://github.com/pytest-dev/pytest-timeout/ Source: https://files.pythonhosted.org/packages/source/p/pytest-timeout/pytest-timeout-%{version}.tar.gz -BuildRequires: %{python_module pexpect} BuildRequires: %{python_module pytest >= 5.0.0} -BuildRequires: %{python_module pytest-cov} BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros Requires: python-pytest >= 5.0.0 +# SECTION test +%if !%{with ringdisabled} +BuildRequires: %{python_module pytest-cov} +%endif +BuildRequires: %{python_module pexpect} +# /SECTION BuildArch: noarch %python_subpackages @@ -42,15 +47,13 @@ integration server or simply if you don't know why the test suite hangs. -Note that while by default on POSIX systems py.test will continue to +Note that while by default on POSIX systems pytest will continue to execute the tests after a test has timed, out this is not always possible. Often the only sure way to interrupt a hanging test is by terminating the entire process. As this is a hard termination (``os._exit()``) it will result in no teardown, JUnit XML output etc. But the plugin will ensure you will have the debugging output on stderr nevertheless, which is the most important part at this stage. -See below for detailed information on the timeout methods and their -side-effects. %prep %setup -q -n pytest-timeout-%{version} @@ -63,14 +66,16 @@ %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -export PYTHONDONTWRITEBYTECODE=1 -%pytest +%if %{with ringdisabled} +donttest="or test_cov" +%endif +%pytest -k "not (donttestprefix $donttest)" %files %{python_files} %license LICENSE %doc README.rst -%{python_sitelib}/pytest_timeout-%{version}-py*.egg-info +%{python_sitelib}/pytest_timeout-%{version}*-info %{python_sitelib}/pytest_timeout.py* -%pycache_only %{python_sitelib}/__pycache__/pytest_timeout*.py* +%pycache_only %{python_sitelib}/__pycache__/pytest_timeout*.pyc %changelog ++++++ pytest-timeout-2.0.2.tar.gz -> pytest-timeout-2.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-timeout-2.0.2/PKG-INFO new/pytest-timeout-2.1.0/PKG-INFO --- old/pytest-timeout-2.0.2/PKG-INFO 2021-12-13 20:32:59.685103200 +0100 +++ new/pytest-timeout-2.1.0/PKG-INFO 2022-01-18 22:33:31.156017000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.2 Name: pytest-timeout -Version: 2.0.2 +Version: 2.1.0 Summary: pytest plugin to abort hanging tests Home-page: https://github.com/pytest-dev/pytest-timeout Author: Floris Bruynooghe @@ -245,9 +245,99 @@ session using ``--pdb`` or similar. + Extending pytest-timeout with plugings + ====================================== + + ``pytest-timeout`` provides two hooks that can be used for extending the tool. These + hooks are used for for setting the timeout timer and cancelling it it the timeout is not + reached. + + For example, ``pytest-asyncio`` can provide asyncio-specific code that generates better + traceback and points on timed out ``await`` instead of the running loop ieration. + + See `pytest hooks documentation + <https://docs.pytest.org/en/latest/how-to/writing_hook_functions.html>`_ for more info + regarding to use custom hooks. + + ``pytest_timeout_set_timer`` + ---------------------------- + + .. code:: python + + @pytest.hookspec(firstresult=True) + def pytest_timeout_set_timer(item, settings): + """Called at timeout setup. + + 'item' is a pytest node to setup timeout for. + + 'settings' is Settings namedtuple (described below). + + Can be overridden by plugins for alternative timeout implementation strategies. + """ + + + ``Settings`` + ------------ + + When ``pytest_timeout_set_timer`` is called, ``settings`` argument is passed. + + The argument has ``Settings`` namedtuple type with the following fields: + + +-----------+-------+--------------------------------------------------------+ + |Attribute | Index | Value | + +===========+=======+========================================================+ + | timeout | 0 | timeout in seconds or ``None`` for no timeout | + +-----------+-------+--------------------------------------------------------+ + | method | 1 | Method mechanism, | + | | | ``'signal'`` and ``'thread'`` are supported by default | + +-----------+-------+--------------------------------------------------------+ + | func_only | 2 | Apply timeout to test function only if ``True``, | + | | | wrap all test function and its fixtures otherwise | + +-----------+-------+--------------------------------------------------------+ + + ``pytest_timeout_cancel_timer`` + ------------------------------- + + .. code:: python + + @pytest.hookspec(firstresult=True) + def pytest_timeout_cancel_timer(item): + """Called at timeout teardown. + + 'item' is a pytest node which was used for timeout setup. + + Can be overridden by plugins for alternative timeout implementation strategies. + """ + + ``is_debugging`` + ---------------- + + When the timeout occurs, user can open the debugger session. In this case, the timeout + should be discarded. A custom hook can check this case by calling ``is_debugging()`` + function: + + .. code:: python + + import pytest + import pytest_timeout + + def on_timeout(): + if pytest_timeout.is_debugging(): + return + pytest.fail("+++ Timeout +++") + + Changelog ========= + 2.1.0 + ----- + + - Get terminal width from shutil instead of deprecated py, thanks + Andrew Svetlov. + - Add an API for extending ``pytest-timeout`` functionality + with third-party plugins, thanks Andrew Svetlov. + 2.0.2 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-timeout-2.0.2/README.rst new/pytest-timeout-2.1.0/README.rst --- old/pytest-timeout-2.0.2/README.rst 2021-12-13 20:27:58.000000000 +0100 +++ new/pytest-timeout-2.1.0/README.rst 2022-01-18 22:33:12.000000000 +0100 @@ -237,9 +237,99 @@ session using ``--pdb`` or similar. +Extending pytest-timeout with plugings +====================================== + +``pytest-timeout`` provides two hooks that can be used for extending the tool. These +hooks are used for for setting the timeout timer and cancelling it it the timeout is not +reached. + +For example, ``pytest-asyncio`` can provide asyncio-specific code that generates better +traceback and points on timed out ``await`` instead of the running loop ieration. + +See `pytest hooks documentation +<https://docs.pytest.org/en/latest/how-to/writing_hook_functions.html>`_ for more info +regarding to use custom hooks. + +``pytest_timeout_set_timer`` +---------------------------- + +.. code:: python + + @pytest.hookspec(firstresult=True) + def pytest_timeout_set_timer(item, settings): + """Called at timeout setup. + + 'item' is a pytest node to setup timeout for. + + 'settings' is Settings namedtuple (described below). + + Can be overridden by plugins for alternative timeout implementation strategies. + """ + + +``Settings`` +------------ + +When ``pytest_timeout_set_timer`` is called, ``settings`` argument is passed. + +The argument has ``Settings`` namedtuple type with the following fields: + ++-----------+-------+--------------------------------------------------------+ +|Attribute | Index | Value | ++===========+=======+========================================================+ +| timeout | 0 | timeout in seconds or ``None`` for no timeout | ++-----------+-------+--------------------------------------------------------+ +| method | 1 | Method mechanism, | +| | | ``'signal'`` and ``'thread'`` are supported by default | ++-----------+-------+--------------------------------------------------------+ +| func_only | 2 | Apply timeout to test function only if ``True``, | +| | | wrap all test function and its fixtures otherwise | ++-----------+-------+--------------------------------------------------------+ + +``pytest_timeout_cancel_timer`` +------------------------------- + +.. code:: python + + @pytest.hookspec(firstresult=True) + def pytest_timeout_cancel_timer(item): + """Called at timeout teardown. + + 'item' is a pytest node which was used for timeout setup. + + Can be overridden by plugins for alternative timeout implementation strategies. + """ + +``is_debugging`` +---------------- + +When the timeout occurs, user can open the debugger session. In this case, the timeout +should be discarded. A custom hook can check this case by calling ``is_debugging()`` +function: + +.. code:: python + + import pytest + import pytest_timeout + + def on_timeout(): + if pytest_timeout.is_debugging(): + return + pytest.fail("+++ Timeout +++") + + Changelog ========= +2.1.0 +----- + +- Get terminal width from shutil instead of deprecated py, thanks + Andrew Svetlov. +- Add an API for extending ``pytest-timeout`` functionality + with third-party plugins, thanks Andrew Svetlov. + 2.0.2 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-timeout-2.0.2/pytest_timeout.egg-info/PKG-INFO new/pytest-timeout-2.1.0/pytest_timeout.egg-info/PKG-INFO --- old/pytest-timeout-2.0.2/pytest_timeout.egg-info/PKG-INFO 2021-12-13 20:32:59.000000000 +0100 +++ new/pytest-timeout-2.1.0/pytest_timeout.egg-info/PKG-INFO 2022-01-18 22:33:30.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.2 Name: pytest-timeout -Version: 2.0.2 +Version: 2.1.0 Summary: pytest plugin to abort hanging tests Home-page: https://github.com/pytest-dev/pytest-timeout Author: Floris Bruynooghe @@ -245,9 +245,99 @@ session using ``--pdb`` or similar. + Extending pytest-timeout with plugings + ====================================== + + ``pytest-timeout`` provides two hooks that can be used for extending the tool. These + hooks are used for for setting the timeout timer and cancelling it it the timeout is not + reached. + + For example, ``pytest-asyncio`` can provide asyncio-specific code that generates better + traceback and points on timed out ``await`` instead of the running loop ieration. + + See `pytest hooks documentation + <https://docs.pytest.org/en/latest/how-to/writing_hook_functions.html>`_ for more info + regarding to use custom hooks. + + ``pytest_timeout_set_timer`` + ---------------------------- + + .. code:: python + + @pytest.hookspec(firstresult=True) + def pytest_timeout_set_timer(item, settings): + """Called at timeout setup. + + 'item' is a pytest node to setup timeout for. + + 'settings' is Settings namedtuple (described below). + + Can be overridden by plugins for alternative timeout implementation strategies. + """ + + + ``Settings`` + ------------ + + When ``pytest_timeout_set_timer`` is called, ``settings`` argument is passed. + + The argument has ``Settings`` namedtuple type with the following fields: + + +-----------+-------+--------------------------------------------------------+ + |Attribute | Index | Value | + +===========+=======+========================================================+ + | timeout | 0 | timeout in seconds or ``None`` for no timeout | + +-----------+-------+--------------------------------------------------------+ + | method | 1 | Method mechanism, | + | | | ``'signal'`` and ``'thread'`` are supported by default | + +-----------+-------+--------------------------------------------------------+ + | func_only | 2 | Apply timeout to test function only if ``True``, | + | | | wrap all test function and its fixtures otherwise | + +-----------+-------+--------------------------------------------------------+ + + ``pytest_timeout_cancel_timer`` + ------------------------------- + + .. code:: python + + @pytest.hookspec(firstresult=True) + def pytest_timeout_cancel_timer(item): + """Called at timeout teardown. + + 'item' is a pytest node which was used for timeout setup. + + Can be overridden by plugins for alternative timeout implementation strategies. + """ + + ``is_debugging`` + ---------------- + + When the timeout occurs, user can open the debugger session. In this case, the timeout + should be discarded. A custom hook can check this case by calling ``is_debugging()`` + function: + + .. code:: python + + import pytest + import pytest_timeout + + def on_timeout(): + if pytest_timeout.is_debugging(): + return + pytest.fail("+++ Timeout +++") + + Changelog ========= + 2.1.0 + ----- + + - Get terminal width from shutil instead of deprecated py, thanks + Andrew Svetlov. + - Add an API for extending ``pytest-timeout`` functionality + with third-party plugins, thanks Andrew Svetlov. + 2.0.2 ----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-timeout-2.0.2/pytest_timeout.py new/pytest-timeout-2.1.0/pytest_timeout.py --- old/pytest-timeout-2.0.2/pytest_timeout.py 2021-11-02 21:30:06.000000000 +0100 +++ new/pytest-timeout-2.1.0/pytest_timeout.py 2022-01-18 20:39:59.000000000 +0100 @@ -8,16 +8,19 @@ """ import inspect import os +import shutil import signal import sys import threading import traceback from collections import namedtuple -import py import pytest +__all__ = ("is_debugging", "Settings") + + HAVE_SIGALRM = hasattr(signal, "SIGALRM") if HAVE_SIGALRM: DEFAULT_METHOD = "signal" @@ -70,6 +73,35 @@ parser.addini("timeout_func_only", FUNC_ONLY_DESC, type="bool") +class TimeoutHooks: + """Timeout specific hooks.""" + + @pytest.hookspec(firstresult=True) + def pytest_timeout_set_timer(item, settings): + """Called at timeout setup. + + 'item' is a pytest node to setup timeout for. + + Can be overridden by plugins for alternative timeout implementation strategies. + + """ + + @pytest.hookspec(firstresult=True) + def pytest_timeout_cancel_timer(item): + """Called at timeout teardown. + + 'item' is a pytest node which was used for timeout setup. + + Can be overridden by plugins for alternative timeout implementation strategies. + + """ + + +def pytest_addhooks(pluginmanager): + """Register timeout-specific hooks.""" + pluginmanager.add_hookspecs(TimeoutHooks) + + @pytest.hookimpl def pytest_configure(config): """Register the marker so it shows up in --markers output.""" @@ -98,12 +130,14 @@ teardown, then this hook installs the timeout. Otherwise pytest_runtest_call is used. """ - func_only = get_func_only_setting(item) - if func_only is False: - timeout_setup(item) + hooks = item.config.pluginmanager.hook + settings = _get_item_settings(item) + is_timeout = settings.timeout is not None and settings.timeout > 0 + if is_timeout and settings.func_only is False: + hooks.pytest_timeout_set_timer(item=item, settings=settings) yield - if func_only is False: - timeout_teardown(item) + if is_timeout and settings.func_only is False: + hooks.pytest_timeout_cancel_timer(item=item) @pytest.hookimpl(hookwrapper=True) @@ -113,12 +147,14 @@ If the timeout is set on only the test function this hook installs the timeout, otherwise pytest_runtest_protocol is used. """ - func_only = get_func_only_setting(item) - if func_only is True: - timeout_setup(item) + hooks = item.config.pluginmanager.hook + settings = _get_item_settings(item) + is_timeout = settings.timeout is not None and settings.timeout > 0 + if is_timeout and settings.func_only is True: + hooks.pytest_timeout_set_timer(item=item, settings=settings) yield - if func_only is True: - timeout_teardown(item) + if is_timeout and settings.func_only is True: + hooks.pytest_timeout_cancel_timer(item=item) @pytest.hookimpl(tryfirst=True) @@ -138,7 +174,8 @@ @pytest.hookimpl(tryfirst=True) def pytest_exception_interact(node): """Stop the timeout when pytest enters pdb in post-mortem mode.""" - timeout_teardown(node) + hooks = node.config.pluginmanager.hook + hooks.pytest_timeout_cancel_timer(item=node) @pytest.hookimpl @@ -187,13 +224,10 @@ SUPPRESS_TIMEOUT = False -def timeout_setup(item): +@pytest.hookimpl(trylast=True) +def pytest_timeout_set_timer(item, settings): """Setup up a timeout trigger and handler.""" - params = get_params(item) - if params.timeout is None or params.timeout <= 0: - return - - timeout_method = params.method + timeout_method = settings.method if ( timeout_method == "signal" and threading.current_thread() is not threading.main_thread() @@ -204,7 +238,7 @@ def handler(signum, frame): __tracebackhide__ = True - timeout_sigalrm(item, params.timeout) + timeout_sigalrm(item, settings.timeout) def cancel(): signal.setitimer(signal.ITIMER_REAL, 0) @@ -212,9 +246,11 @@ item.cancel_timeout = cancel signal.signal(signal.SIGALRM, handler) - signal.setitimer(signal.ITIMER_REAL, params.timeout) + signal.setitimer(signal.ITIMER_REAL, settings.timeout) elif timeout_method == "thread": - timer = threading.Timer(params.timeout, timeout_timer, (item, params.timeout)) + timer = threading.Timer( + settings.timeout, timeout_timer, (item, settings.timeout) + ) timer.name = "%s %s" % (__name__, item.nodeid) def cancel(): @@ -223,9 +259,11 @@ item.cancel_timeout = cancel timer.start() + return True -def timeout_teardown(item): +@pytest.hookimpl(trylast=True) +def pytest_timeout_cancel_timer(item): """Cancel the timeout trigger if it was set.""" # When skipping is raised from a pytest_runtest_setup function # (as is the case when using the pytest.mark.skipif marker) we @@ -234,6 +272,7 @@ cancel = getattr(item, "cancel_timeout", None) if cancel: cancel() + return True def get_env_settings(config): @@ -268,21 +307,7 @@ return Settings(timeout, method, func_only or False) -def get_func_only_setting(item): - """Return the func_only setting for an item.""" - func_only = None - marker = item.get_closest_marker("timeout") - if marker: - settings = get_params(item, marker=marker) - func_only = _validate_func_only(settings.func_only, "marker") - if func_only is None: - func_only = item.config._env_timeout_func_only - if func_only is None: - func_only = False - return func_only - - -def get_params(item, marker=None): +def _get_item_settings(item, marker=None): """Return (timeout, method) for an item.""" timeout = method = func_only = None if not marker: @@ -298,6 +323,8 @@ method = item.config._env_timeout_method if func_only is None: func_only = item.config._env_timeout_func_only + if func_only is None: + func_only = False return Settings(timeout, method, func_only) @@ -444,7 +471,7 @@ """ if stream is None: stream = sys.stderr - width = py.io.get_terminal_width() + width, height = shutil.get_terminal_size() fill = int((width - len(title) - 2) / 2) line = " ".join([sep * fill, title, sep * fill]) if len(line) < width: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-timeout-2.0.2/setup.py new/pytest-timeout-2.1.0/setup.py --- old/pytest-timeout-2.0.2/setup.py 2021-12-13 20:28:29.000000000 +0100 +++ new/pytest-timeout-2.1.0/setup.py 2022-01-18 22:21:44.000000000 +0100 @@ -9,7 +9,7 @@ name="pytest-timeout", description="pytest plugin to abort hanging tests", long_description=long_description, - version="2.0.2", + version="2.1.0", author="Floris Bruynooghe", author_email="flub@devork.be", url="https://github.com/pytest-dev/pytest-timeout", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-timeout-2.0.2/test_pytest_timeout.py new/pytest-timeout-2.1.0/test_pytest_timeout.py --- old/pytest-timeout-2.0.2/test_pytest_timeout.py 2021-11-02 21:30:06.000000000 +0100 +++ new/pytest-timeout-2.1.0/test_pytest_timeout.py 2022-01-18 20:39:59.000000000 +0100 @@ -506,3 +506,39 @@ result.stdout.fnmatch_lines( ["timeout: 1.0s", "timeout method:*", "timeout func_only:*"] ) + + +def test_plugin_interface(testdir): + testdir.makeconftest( + """ + import pytest + + @pytest.mark.tryfirst + def pytest_timeout_set_timer(item, settings): + print() + print("pytest_timeout_set_timer") + return True + + @pytest.mark.tryfirst + def pytest_timeout_cancel_timer(item): + print() + print("pytest_timeout_cancel_timer") + return True + """ + ) + testdir.makepyfile( + """ + import pytest + + @pytest.mark.timeout(1) + def test_foo(): + pass + """ + ) + result = testdir.runpytest("-s") + result.stdout.fnmatch_lines( + [ + "pytest_timeout_set_timer", + "pytest_timeout_cancel_timer", + ] + )
participants (1)
-
Source-Sync