Hello community,
here is the log from the commit of package python-pytest-asyncio for openSUSE:Factory checked in at 2020-06-30 21:54:46
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pytest-asyncio (Old)
and /work/SRC/openSUSE:Factory/.python-pytest-asyncio.new.3060 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pytest-asyncio"
Tue Jun 30 21:54:46 2020 rev:6 rq:817722 version:0.14.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-pytest-asyncio/python-pytest-asyncio.changes 2020-06-11 14:46:04.365622099 +0200
+++ /work/SRC/openSUSE:Factory/.python-pytest-asyncio.new.3060/python-pytest-asyncio.changes 2020-06-30 21:54:48.810452206 +0200
@@ -1,0 +2,6 @@
+Mon Jun 29 09:10:04 UTC 2020 - Marketa Calabkova
+
+- Update to 0.14.0
+ * Fix #162, and event_loop fixture behavior now is coherent on all scopes.
+
+-------------------------------------------------------------------
Old:
----
pytest-asyncio-0.12.0.tar.gz
New:
----
pytest-asyncio-0.14.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-pytest-asyncio.spec ++++++
--- /var/tmp/diff_new_pack.VlUoKA/_old 2020-06-30 21:54:50.250456662 +0200
+++ /var/tmp/diff_new_pack.VlUoKA/_new 2020-06-30 21:54:50.254456674 +0200
@@ -19,12 +19,12 @@
%define skip_python2 1
%{?!python_module:%define python_module() python3-%{**}}
Name: python-pytest-asyncio
-Version: 0.12.0
+Version: 0.14.0
Release: 0
Summary: Pytest support for asyncio
License: Apache-2.0
URL: https://github.com/pytest-dev/pytest-asyncio
-Source: https://github.com/pytest-dev/pytest-asyncio/archive/v%{version}.tar.gz#./pytest-asyncio-%{version}.tar.gz
+Source: https://github.com/pytest-dev/pytest-asyncio/archive/v%{version}.tar.gz#/pytest-asyncio-%{version}.tar.gz
BuildRequires: %{python_module async_generator >= 1.3}
BuildRequires: %{python_module base >= 3.6}
BuildRequires: %{python_module hypothesis >= 5.7.1}
++++++ pytest-asyncio-0.12.0.tar.gz -> pytest-asyncio-0.14.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-asyncio-0.12.0/README.rst new/pytest-asyncio-0.14.0/README.rst
--- old/pytest-asyncio-0.12.0/README.rst 2020-05-04 00:47:14.000000000 +0200
+++ new/pytest-asyncio-0.14.0/README.rst 2020-06-24 00:12:15.000000000 +0200
@@ -175,28 +175,32 @@
Changelog
---------
+0.13.0 (2020-06-24)
+~~~~~~~~~~~~~~~~~~~
+- Fix `#162 https://github.com/pytest-dev/pytest-asyncio/issues/162`_, and ``event_loop`` fixture behavior now is coherent on all scopes.
+ `#164 https://github.com/pytest-dev/pytest-asyncio/pull/164`_
0.12.0 (2020-05-04)
~~~~~~~~~~~~~~~~~~~
- Run the event loop fixture as soon as possible. This helps with fixtures that have an implicit dependency on the event loop.
- `#156` https://github.com/pytest-dev/pytest-asyncio/pull/156
+ `#156 https://github.com/pytest-dev/pytest-asyncio/pull/156`_
0.11.0 (2020-04-20)
~~~~~~~~~~~~~~~~~~~
- Test on 3.8, drop 3.3 and 3.4. Stick to 0.10 for these versions.
- `#152` https://github.com/pytest-dev/pytest-asyncio/pull/152
+ `#152 https://github.com/pytest-dev/pytest-asyncio/pull/152`_
- Use the new Pytest 5.4.0 Function API. We therefore depend on pytest >= 5.4.0.
- `#142` https://github.com/pytest-dev/pytest-asyncio/pull/142
+ `#142 https://github.com/pytest-dev/pytest-asyncio/pull/142`_
- Better ``pytest.skip`` support.
- `#126` https://github.com/pytest-dev/pytest-asyncio/pull/126
+ `#126 https://github.com/pytest-dev/pytest-asyncio/pull/126`_
0.10.0 (2019-01-08)
~~~~~~~~~~~~~~~~~~~~
- ``pytest-asyncio`` integrates with `Hypothesis https://hypothesis.readthedocs.io`_
to support ``@given`` on async test functions using ``asyncio``.
- `#102` https://github.com/pytest-dev/pytest-asyncio/pull/102
+ `#102 https://github.com/pytest-dev/pytest-asyncio/pull/102`_
- Pytest 4.1 support.
- `#105` https://github.com/pytest-dev/pytest-asyncio/pull/105
+ `#105 https://github.com/pytest-dev/pytest-asyncio/pull/105`_
0.9.0 (2018-07-28)
~~~~~~~~~~~~~~~~~~
@@ -208,7 +212,7 @@
0.8.0 (2017-09-23)
~~~~~~~~~~~~~~~~~~
- Improve integration with other packages (like aiohttp) with more careful event loop handling.
- `#64` https://github.com/pytest-dev/pytest-asyncio/pull/64
+ `#64 https://github.com/pytest-dev/pytest-asyncio/pull/64`_
0.7.0 (2017-09-08)
~~~~~~~~~~~~~~~~~~
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-asyncio-0.12.0/pytest_asyncio/__init__.py new/pytest-asyncio-0.14.0/pytest_asyncio/__init__.py
--- old/pytest-asyncio-0.12.0/pytest_asyncio/__init__.py 2020-05-04 00:47:14.000000000 +0200
+++ new/pytest-asyncio-0.14.0/pytest_asyncio/__init__.py 2020-06-24 00:12:15.000000000 +0200
@@ -1,2 +1,2 @@
"""The main point for importing pytest-asyncio items."""
-__version__ = "0.12.0"
+__version__ = "0.14.0"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-asyncio-0.12.0/pytest_asyncio/plugin.py new/pytest-asyncio-0.14.0/pytest_asyncio/plugin.py
--- old/pytest-asyncio-0.12.0/pytest_asyncio/plugin.py 2020-05-04 00:47:14.000000000 +0200
+++ new/pytest-asyncio-0.14.0/pytest_asyncio/plugin.py 2020-06-24 00:12:15.000000000 +0200
@@ -48,36 +48,61 @@
return list(collector._genfunctions(name, obj))
+class FixtureStripper:
+ """Include additional Fixture, and then strip them"""
+ REQUEST = "request"
+ EVENT_LOOP = "event_loop"
+
+ def __init__(self, fixturedef):
+ self.fixturedef = fixturedef
+ self.to_strip = set()
+
+ def add(self, name):
+ """Add fixture name to fixturedef
+ and record in to_strip list (If not previously included)"""
+ if name in self.fixturedef.argnames:
+ return
+ self.fixturedef.argnames += (name, )
+ self.to_strip.add(name)
+
+ def get_and_strip_from(self, name, data_dict):
+ """Strip name from data, and return value"""
+ result = data_dict[name]
+ if name in self.to_strip:
+ del data_dict[name]
+ return result
+
+@pytest.hookimpl(trylast=True)
+def pytest_fixture_post_finalizer(fixturedef, request):
+ """Called after fixture teardown"""
+ if fixturedef.argname == "event_loop":
+ # Set empty loop policy, so that subsequent get_event_loop() provides a new loop
+ asyncio.set_event_loop_policy(None)
+
+
+
@pytest.hookimpl(hookwrapper=True)
def pytest_fixture_setup(fixturedef, request):
"""Adjust the event loop policy when an event loop is produced."""
- if fixturedef.argname == "event_loop" and 'asyncio' in request.keywords:
+ if fixturedef.argname == "event_loop":
outcome = yield
loop = outcome.get_result()
policy = asyncio.get_event_loop_policy()
- try:
- old_loop = policy.get_event_loop()
- except RuntimeError as exc:
- if 'no current event loop' not in str(exc):
- raise
- old_loop = None
policy.set_event_loop(loop)
- fixturedef.addfinalizer(lambda: policy.set_event_loop(old_loop))
return
if isasyncgenfunction(fixturedef.func):
# This is an async generator function. Wrap it accordingly.
generator = fixturedef.func
- strip_request = False
- if 'request' not in fixturedef.argnames:
- fixturedef.argnames += ('request', )
- strip_request = True
+ fixture_stripper = FixtureStripper(fixturedef)
+ fixture_stripper.add(FixtureStripper.EVENT_LOOP)
+ fixture_stripper.add(FixtureStripper.REQUEST)
+
def wrapper(*args, **kwargs):
- request = kwargs['request']
- if strip_request:
- del kwargs['request']
+ loop = fixture_stripper.get_and_strip_from(FixtureStripper.EVENT_LOOP, kwargs)
+ request = fixture_stripper.get_and_strip_from(FixtureStripper.REQUEST, kwargs)
gen_obj = generator(*args, **kwargs)
@@ -96,21 +121,26 @@
msg = "Async generator fixture didn't stop."
msg += "Yield only once."
raise ValueError(msg)
- asyncio.get_event_loop().run_until_complete(async_finalizer())
+ loop.run_until_complete(async_finalizer())
request.addfinalizer(finalizer)
- return asyncio.get_event_loop().run_until_complete(setup())
+ return loop.run_until_complete(setup())
fixturedef.func = wrapper
elif inspect.iscoroutinefunction(fixturedef.func):
coro = fixturedef.func
+ fixture_stripper = FixtureStripper(fixturedef)
+ fixture_stripper.add(FixtureStripper.EVENT_LOOP)
+
def wrapper(*args, **kwargs):
+ loop = fixture_stripper.get_and_strip_from(FixtureStripper.EVENT_LOOP, kwargs)
+
async def setup():
res = await coro(*args, **kwargs)
return res
- return asyncio.get_event_loop().run_until_complete(setup())
+ return loop.run_until_complete(setup())
fixturedef.func = wrapper
yield
@@ -144,15 +174,9 @@
def inner(**kwargs):
coro = func(**kwargs)
if coro is not None:
+ task = asyncio.ensure_future(coro, loop=_loop)
try:
- loop = asyncio.get_event_loop()
- except RuntimeError as exc:
- if 'no current event loop' not in str(exc):
- raise
- loop = _loop
- task = asyncio.ensure_future(coro, loop=loop)
- try:
- loop.run_until_complete(task)
+ _loop.run_until_complete(task)
except BaseException:
# run_until_complete doesn't get the result from exceptions
# that are not subclasses of `Exception`. Consume all
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-asyncio-0.12.0/tests/async_fixtures/test_async_fixtures_with_finalizer.py new/pytest-asyncio-0.14.0/tests/async_fixtures/test_async_fixtures_with_finalizer.py
--- old/pytest-asyncio-0.12.0/tests/async_fixtures/test_async_fixtures_with_finalizer.py 1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.14.0/tests/async_fixtures/test_async_fixtures_with_finalizer.py 2020-06-24 00:12:15.000000000 +0200
@@ -0,0 +1,50 @@
+import asyncio
+import functools
+import pytest
+
+
+@pytest.mark.asyncio
+async def test_module_with_event_loop_finalizer(port_with_event_loop_finalizer):
+ await asyncio.sleep(0.01)
+ assert port_with_event_loop_finalizer
+
+@pytest.mark.asyncio
+async def test_module_with_get_event_loop_finalizer(port_with_get_event_loop_finalizer):
+ await asyncio.sleep(0.01)
+ assert port_with_get_event_loop_finalizer
+
+@pytest.fixture(scope="module")
+def event_loop():
+ """Change event_loop fixture to module level."""
+ policy = asyncio.get_event_loop_policy()
+ loop = policy.new_event_loop()
+ yield loop
+ loop.close()
+
+
+@pytest.fixture(scope="module")
+async def port_with_event_loop_finalizer(request, event_loop):
+ def port_finalizer(finalizer):
+ async def port_afinalizer():
+ # await task using loop provided by event_loop fixture
+ # RuntimeError is raised if task is created on a different loop
+ await finalizer
+ event_loop.run_until_complete(port_afinalizer())
+
+ worker = asyncio.ensure_future(asyncio.sleep(0.2))
+ request.addfinalizer(functools.partial(port_finalizer, worker))
+ return True
+
+
+@pytest.fixture(scope="module")
+async def port_with_get_event_loop_finalizer(request, event_loop):
+ def port_finalizer(finalizer):
+ async def port_afinalizer():
+ # await task using loop provided by asyncio.get_event_loop()
+ # RuntimeError is raised if task is created on a different loop
+ await finalizer
+ asyncio.get_event_loop().run_until_complete(port_afinalizer())
+
+ worker = asyncio.ensure_future(asyncio.sleep(0.2))
+ request.addfinalizer(functools.partial(port_finalizer, worker))
+ return True