Hello community,
here is the log from the commit of package python-pytest-asyncio for
openSUSE:Factory checked in at 2018-09-11 17:14:57
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pytest-asyncio (Old)
and /work/SRC/openSUSE:Factory/.python-pytest-asyncio.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pytest-asyncio"
Tue Sep 11 17:14:57 2018 rev:2 rq:633035 version:0.9.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-pytest-asyncio/python-pytest-asyncio.changes
2018-03-05 13:45:36.675108492 +0100
+++
/work/SRC/openSUSE:Factory/.python-pytest-asyncio.new/python-pytest-asyncio.changes
2018-09-11 17:15:03.127617477 +0200
@@ -1,0 +2,9 @@
+Tue Sep 4 13:10:57 UTC 2018 - Ondřej Súkup <[email protected]>
+
+- update to 0.9.0
+- use github tarbal due packaging errrors in upstream
+ * Python 3.7 support.
+ * Remove event_loop_process_pool fixture
+ and pytest.mark.asyncio_process_pool marker
+
+-------------------------------------------------------------------
Old:
----
pytest-asyncio-0.8.0.tar.gz
New:
----
pytest-asyncio-0.9.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-pytest-asyncio.spec ++++++
--- /var/tmp/diff_new_pack.SMLGma/_old 2018-09-11 17:15:08.199609655 +0200
+++ /var/tmp/diff_new_pack.SMLGma/_new 2018-09-11 17:15:08.199609655 +0200
@@ -13,28 +13,29 @@
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
-%define skip_python2 1
+%define skip_python2 1
%{?!python_module:%define python_module() python3-%{**}}
Name: python-pytest-asyncio
-Version: 0.8.0
+Version: 0.9.0
Release: 0
-License: Apache-2.0
Summary: Pytest support for asyncio
-Url: https://github.com/pytest-dev/pytest-asyncio
+License: Apache-2.0
Group: Development/Languages/Python
-Source:
https://files.pythonhosted.org/packages/source/p/pytest-asyncio/pytest-asyncio-%{version}.tar.gz
-BuildRequires: python-rpm-macros
-BuildRequires: %{python_module devel} >= 3.5
+URL: https://github.com/pytest-dev/pytest-asyncio
+#Source:
https://files.pythonhosted.org/packages/source/p/pytest-asyncio/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}
+BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
+BuildRequires: python-rpm-macros
Requires: python-pytest >= 3.0.6
Suggests: python-async_generator >= 1.3
Suggests: python-coverage
-Suggests: python-async_generator >= 1.3
BuildArch: noarch
-
%python_subpackages
%description
@@ -55,8 +56,10 @@
%python_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}
+%check
+%python_exec -m pytest
+
%files %{python_files}
-%defattr(-,root,root,-)
%doc README.rst
%license LICENSE
%{python_sitelib}/*
++++++ pytest-asyncio-0.8.0.tar.gz -> pytest-asyncio-0.9.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/.gitignore
new/pytest-asyncio-0.9.0/.gitignore
--- old/pytest-asyncio-0.8.0/.gitignore 1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/.gitignore 2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,60 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+.venv*
+.idea
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/.travis.yml
new/pytest-asyncio-0.9.0/.travis.yml
--- old/pytest-asyncio-0.8.0/.travis.yml 1970-01-01 01:00:00.000000000
+0100
+++ new/pytest-asyncio-0.9.0/.travis.yml 2018-07-28 16:33:29.000000000
+0200
@@ -0,0 +1,21 @@
+language: python
+matrix:
+ include:
+ - python: 3.5
+ env: TOX_ENV=py35
+ - python: 3.6
+ env: TOX_ENV=py36
+ - python: 3.7
+ env: TOX_ENV=py37
+ # TODO: the dist and sudo keys are currently needed to use Python 3.7.
+ # They should be removed once Travis-CI supports 3.7 on the default
image.
+ dist: xenial
+ sudo: true
+
+install: pip install tox-travis coveralls
+
+script: tox -e $TOX_ENV
+
+after_success:
+ - tox -e coverage-report
+ - coveralls
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/PKG-INFO
new/pytest-asyncio-0.9.0/PKG-INFO
--- old/pytest-asyncio-0.8.0/PKG-INFO 2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/PKG-INFO 1970-01-01 01:00:00.000000000 +0100
@@ -1,276 +0,0 @@
-Metadata-Version: 1.2
-Name: pytest-asyncio
-Version: 0.8.0
-Summary: Pytest support for asyncio.
-Home-page: https://github.com/pytest-dev/pytest-asyncio
-Author: Tin Tvrtković
-Author-email: [email protected]
-License: Apache 2.0
-Description-Content-Type: UNKNOWN
-Description: pytest-asyncio: pytest support for asyncio
- ==========================================
-
- .. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg
- :target: https://pypi.python.org/pypi/pytest-asyncio
- .. image::
https://travis-ci.org/pytest-dev/pytest-asyncio.svg?branch=master
- :target: https://travis-ci.org/pytest-dev/pytest-asyncio
- .. image::
https://coveralls.io/repos/pytest-dev/pytest-asyncio/badge.svg
- :target: https://coveralls.io/r/pytest-dev/pytest-asyncio
-
- pytest-asyncio is an Apache2 licensed library, written in Python, for
testing
- asyncio code with pytest.
-
- asyncio code is usually written in the form of coroutines, which makes
it
- slightly more difficult to test using normal testing tools.
pytest-asyncio
- provides useful fixtures and markers to make testing easier.
-
- .. code-block:: python
-
- @pytest.mark.asyncio
- async def test_some_asyncio_code():
- res = await library.do_something()
- assert b'expected result' == res
-
- pytest-asyncio has been strongly influenced by pytest-tornado_.
-
- .. _pytest-tornado: https://github.com/eugeniy/pytest-tornado
-
- Features
- --------
-
- - fixtures for creating and injecting versions of the asyncio event
loop
- - fixtures for injecting unused tcp ports
- - pytest markers for treating tests as asyncio coroutines
- - easy testing with non-default event loops
- - support for `async def` fixtures and async generator fixtures
-
- Installation
- ------------
-
- To install pytest-asyncio, simply:
-
- .. code-block:: bash
-
- $ pip install pytest-asyncio
-
- This is enough for pytest to pick up pytest-asyncio.
-
- Fixtures
- --------
-
- ``event_loop``
- ~~~~~~~~~~~~~~
- Creates and injects a new instance of the default asyncio event loop.
By
- default, the loop will be closed at the end of the test (i.e. the
default
- fixture scope is ``function``).
-
- Note that just using the ``event_loop`` fixture won't make your test
function
- a coroutine. You'll need to interact with the event loop directly,
using methods
- like ``event_loop.run_until_complete``. See the
``pytest.mark.asyncio`` marker
- for treating test functions like coroutines.
-
- Simply using this fixture will not set the generated event loop as the
- default asyncio event loop, or change the asyncio event loop policy in
any way.
- Use ``pytest.mark.asyncio`` for this purpose.
-
- .. code-block:: python
-
- def test_http_client(event_loop):
- url = 'http://httpbin.org/get'
- resp = event_loop.run_until_complete(http_client(url))
- assert b'HTTP/1.1 200 OK' in resp
-
- This fixture can be easily overridden in any of the standard pytest
locations
- (e.g. directly in the test file, or in ``conftest.py``) to use a
non-default
- event loop. This will take effect even if you're using the
- ``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture
directly.
-
- .. code-block:: python
-
- @pytest.yield_fixture()
- def event_loop():
- loop = MyCustomLoop()
- yield loop
- loop.close()
-
- If the ``pytest.mark.asyncio`` marker is applied, a pytest hook will
- ensure the produced loop is set as the default global loop.
- Fixtures depending on the ``event_loop`` fixture can expect the policy
to be properly modified when they run.
-
- ``event_loop_process_pool``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- The ``event_loop_process_pool`` fixture is almost identical to the
- ``event_loop`` fixture, except the created event loop will have a
- ``concurrent.futures.ProcessPoolExecutor`` set as the default executor.
-
- ``unused_tcp_port``
- ~~~~~~~~~~~~~~~~~~~
- Finds and yields a single unused TCP port on the localhost interface.
Useful for
- binding temporary test servers.
-
- ``unused_tcp_port_factory``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- A callable which returns a different unused TCP port each invocation.
Useful
- when several unused TCP ports are required in a test.
-
- .. code-block:: python
-
- def a_test(unused_tcp_port_factory):
- port1, port2 = unused_tcp_port_factory(),
unused_tcp_port_factory()
- ...
-
- Async fixtures
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Asynchronous fixtures are defined just like ordinary pytest fixtures,
except they should be coroutines or asynchronous generators.
-
- .. code-block:: python3
-
- @pytest.fixture
- async def async_gen_fixture():
- await asyncio.sleep(0.1)
- yield 'a value'
-
- @pytest.fixture(scope='module')
- async def async_fixture():
- return await asyncio.sleep(0.1)
-
- All scopes are supported, but if you use a non-function scope you will
need
- to redefine the ``event_loop`` fixture to have the same or broader
scope.
- Async fixtures need the event loop, and so must have the same or
narrower scope
- than the ``event_loop`` fixture.
-
- If you want to do this with Python 3.5, the ``yield`` statement must
be replaced with ``await yield_()`` and the coroutine
- function must be decorated with ``@async_generator``, like so:
-
- .. code-block:: python3
-
- from async_generator import yield_, async_generator
-
- @pytest.fixture
- @async_generator
- async def async_gen_fixture():
- await asyncio.sleep(0.1)
- await yield_('a value')
-
-
- Markers
- -------
-
- ``pytest.mark.asyncio``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Mark your test coroutine with this marker and pytest will execute it
as an
- asyncio task using the event loop provided by the ``event_loop``
fixture. See
- the introductory section for an example.
-
- The event loop used can be overriden by overriding the ``event_loop``
fixture
- (see above).
-
- In order to make your test code a little more concise, the pytest
|pytestmark|_
- feature can be used to mark entire modules or classes with this marker.
- Only test coroutines will be affected (by default, coroutines prefixed
by
- ``test_``), so, for example, fixtures are safe to define.
-
- .. code-block:: python
-
- import asyncio
- import pytest
-
- # All test coroutines will be treated as marked.
- pytestmark = pytest.mark.asyncio
-
- async def test_example(event_loop):
- """No marker!"""
- await asyncio.sleep(0, loop=event_loop)
-
- .. |pytestmark| replace:: ``pytestmark``
- .. _pytestmark:
http://doc.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules
-
- ``pytest.mark.asyncio_process_pool``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- The ``asyncio_process_pool`` marker is almost identical to the
``asyncio``
- marker, except the event loop used will have a
- ``concurrent.futures.ProcessPoolExecutor`` set as the default executor.
-
- Changelog
- ---------
-
- 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>
-
- 0.7.0 (2017-09-08)
- ~~~~~~~~~~~~~~~~~~
- - Python versions pre-3.6 can use the async_generator library for
async fixtures.
- `#62 <https://github.com/pytest-dev/pytest-asyncio/pull/62>`
-
-
- 0.6.0 (2017-05-28)
- ~~~~~~~~~~~~~~~~~~
- - Support for Python versions pre-3.5 has been dropped.
- - ``pytestmark`` now works on both module and class level.
- - The ``forbid_global_loop`` parameter has been removed.
- - Support for async and async gen fixtures has been added.
- `#45 <https://github.com/pytest-dev/pytest-asyncio/pull/45>`_
- - The deprecation warning regarding ``asyncio.async()`` has been fixed.
- `#51 <https://github.com/pytest-dev/pytest-asyncio/pull/51>`_
-
- 0.5.0 (2016-09-07)
- ~~~~~~~~~~~~~~~~~~
- - Introduced a changelog.
- `#31 <https://github.com/pytest-dev/pytest-asyncio/issues/31>`_
- - The ``event_loop`` fixture is again responsible for closing itself.
- This makes the fixture slightly harder to correctly override, but
enables
- other fixtures to depend on it correctly.
- `#30 <https://github.com/pytest-dev/pytest-asyncio/issues/30>`_
- - Deal with the event loop policy by wrapping a special pytest hook,
- ``pytest_fixture_setup``. This allows setting the policy before
fixtures
- dependent on the ``event_loop`` fixture run, thus allowing them to
take
- advantage of the ``forbid_global_loop`` parameter. As a consequence
of this,
- we now depend on pytest 3.0.
- `#29 <https://github.com/pytest-dev/pytest-asyncio/issues/29>`_
-
-
- 0.4.1 (2016-06-01)
- ~~~~~~~~~~~~~~~~~~
- - Fix a bug preventing the propagation of exceptions from the plugin.
- `#25 <https://github.com/pytest-dev/pytest-asyncio/issues/25>`_
-
- 0.4.0 (2016-05-30)
- ~~~~~~~~~~~~~~~~~~
- - Make ``event_loop`` fixtures simpler to override by closing them in
the
- plugin, instead of directly in the fixture.
- `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_
- - Introduce the ``forbid_global_loop`` parameter.
- `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_
-
- 0.3.0 (2015-12-19)
- ~~~~~~~~~~~~~~~~~~
- - Support for Python 3.5 ``async``/``await`` syntax.
- `#17 <https://github.com/pytest-dev/pytest-asyncio/pull/17>`_
-
- 0.2.0 (2015-08-01)
- ~~~~~~~~~~~~~~~~~~
- - ``unused_tcp_port_factory`` fixture.
- `#10 <https://github.com/pytest-dev/pytest-asyncio/issues/10>`_
-
-
- 0.1.1 (2015-04-23)
- ~~~~~~~~~~~~~~~~~~
- Initial release.
-
-
- Contributing
- ------------
- Contributions are very welcome. Tests can be run with ``tox``, please
ensure
- the coverage at least stays the same before you submit a pull request.
-
-Platform: UNKNOWN
-Classifier: Development Status :: 4 - Beta
-Classifier: Intended Audience :: Developers
-Classifier: License :: OSI Approved :: Apache Software License
-Classifier: Programming Language :: Python :: 3.5
-Classifier: Programming Language :: Python :: 3.6
-Classifier: Topic :: Software Development :: Testing
-Classifier: Framework :: Pytest
-Requires-Python: >= 3.5
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/README.rst
new/pytest-asyncio-0.9.0/README.rst
--- old/pytest-asyncio-0.8.0/README.rst 2017-09-23 13:35:46.000000000 +0200
+++ new/pytest-asyncio-0.9.0/README.rst 2018-07-28 16:33:29.000000000 +0200
@@ -7,6 +7,9 @@
:target: https://travis-ci.org/pytest-dev/pytest-asyncio
.. image:: https://coveralls.io/repos/pytest-dev/pytest-asyncio/badge.svg
:target: https://coveralls.io/r/pytest-dev/pytest-asyncio
+.. image:: https://img.shields.io/pypi/pyversions/pytest-asyncio.svg
+ :target: https://github.com/pytest-dev/pytest-asyncio
+ :alt: Supported Python versions
pytest-asyncio is an Apache2 licensed library, written in Python, for testing
asyncio code with pytest.
@@ -88,12 +91,6 @@
ensure the produced loop is set as the default global loop.
Fixtures depending on the ``event_loop`` fixture can expect the policy to be
properly modified when they run.
-``event_loop_process_pool``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The ``event_loop_process_pool`` fixture is almost identical to the
-``event_loop`` fixture, except the created event loop will have a
-``concurrent.futures.ProcessPoolExecutor`` set as the default executor.
-
``unused_tcp_port``
~~~~~~~~~~~~~~~~~~~
Finds and yields a single unused TCP port on the localhost interface. Useful
for
@@ -176,15 +173,16 @@
.. |pytestmark| replace:: ``pytestmark``
.. _pytestmark:
http://doc.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules
-``pytest.mark.asyncio_process_pool``
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The ``asyncio_process_pool`` marker is almost identical to the ``asyncio``
-marker, except the event loop used will have a
-``concurrent.futures.ProcessPoolExecutor`` set as the default executor.
-
Changelog
---------
+0.9.0 (2018-07-28)
+~~~~~~~~~~~~~~~~~~
+- Python 3.7 support.
+- Remove ``event_loop_process_pool`` fixture and
+ ``pytest.mark.asyncio_process_pool`` marker (see
+ https://bugs.python.org/issue34075 for deprecation and removal details)
+
0.8.0 (2017-09-23)
~~~~~~~~~~~~~~~~~~
- Improve integration with other packages (like aiohttp) with more careful
event loop handling.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/pytest_asyncio/__init__.py
new/pytest-asyncio-0.9.0/pytest_asyncio/__init__.py
--- old/pytest-asyncio-0.8.0/pytest_asyncio/__init__.py 2017-09-23
13:35:52.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio/__init__.py 2018-07-28
16:33:29.000000000 +0200
@@ -1,2 +1,2 @@
"""The main point for importing pytest-asyncio items."""
-__version__ = '0.8.0'
+__version__ = "0.9.0"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/pytest_asyncio/plugin.py
new/pytest-asyncio-0.9.0/pytest_asyncio/plugin.py
--- old/pytest-asyncio-0.8.0/pytest_asyncio/plugin.py 2017-09-23
13:18:06.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio/plugin.py 2018-07-28
16:33:29.000000000 +0200
@@ -3,7 +3,6 @@
import contextlib
import inspect
import socket
-from concurrent.futures import ProcessPoolExecutor
import pytest
from _pytest.python import transfer_markers
@@ -25,11 +24,6 @@
"asyncio: "
"mark the test as a coroutine, it will be "
"run using an asyncio event loop")
- config.addinivalue_line("markers",
- "asyncio_process_pool: "
- "mark the test as a coroutine, it will be "
- "run using an asyncio event loop with a process "
- "pool")
@pytest.mark.tryfirst
@@ -44,8 +38,7 @@
transfer_markers(obj, item.cls, item.module)
item = pytest.Function(name, parent=collector) # To reload keywords.
- if ('asyncio' in item.keywords or
- 'asyncio_process_pool' in item.keywords):
+ if 'asyncio' in item.keywords:
return list(collector._genfunctions(name, obj))
@@ -170,7 +163,6 @@
# to marked test functions
_markers_2_fixtures = {
'asyncio': 'event_loop',
- 'asyncio_process_pool': 'event_loop_process_pool',
}
@@ -183,15 +175,6 @@
@pytest.fixture
-def event_loop_process_pool(event_loop):
- """Create a fresh instance of the default event loop.
-
- The event loop will have a process pool set as the default executor."""
- event_loop.set_default_executor(ProcessPoolExecutor())
- return event_loop
-
-
[email protected]
def unused_tcp_port():
"""Find an unused localhost TCP port from 1024-65535 and return it."""
with contextlib.closing(socket.socket()) as sock:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/PKG-INFO
new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/PKG-INFO
--- old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/PKG-INFO 2017-09-23
13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/PKG-INFO 1970-01-01
01:00:00.000000000 +0100
@@ -1,276 +0,0 @@
-Metadata-Version: 1.2
-Name: pytest-asyncio
-Version: 0.8.0
-Summary: Pytest support for asyncio.
-Home-page: https://github.com/pytest-dev/pytest-asyncio
-Author: Tin Tvrtković
-Author-email: [email protected]
-License: Apache 2.0
-Description-Content-Type: UNKNOWN
-Description: pytest-asyncio: pytest support for asyncio
- ==========================================
-
- .. image:: https://img.shields.io/pypi/v/pytest-asyncio.svg
- :target: https://pypi.python.org/pypi/pytest-asyncio
- .. image::
https://travis-ci.org/pytest-dev/pytest-asyncio.svg?branch=master
- :target: https://travis-ci.org/pytest-dev/pytest-asyncio
- .. image::
https://coveralls.io/repos/pytest-dev/pytest-asyncio/badge.svg
- :target: https://coveralls.io/r/pytest-dev/pytest-asyncio
-
- pytest-asyncio is an Apache2 licensed library, written in Python, for
testing
- asyncio code with pytest.
-
- asyncio code is usually written in the form of coroutines, which makes
it
- slightly more difficult to test using normal testing tools.
pytest-asyncio
- provides useful fixtures and markers to make testing easier.
-
- .. code-block:: python
-
- @pytest.mark.asyncio
- async def test_some_asyncio_code():
- res = await library.do_something()
- assert b'expected result' == res
-
- pytest-asyncio has been strongly influenced by pytest-tornado_.
-
- .. _pytest-tornado: https://github.com/eugeniy/pytest-tornado
-
- Features
- --------
-
- - fixtures for creating and injecting versions of the asyncio event
loop
- - fixtures for injecting unused tcp ports
- - pytest markers for treating tests as asyncio coroutines
- - easy testing with non-default event loops
- - support for `async def` fixtures and async generator fixtures
-
- Installation
- ------------
-
- To install pytest-asyncio, simply:
-
- .. code-block:: bash
-
- $ pip install pytest-asyncio
-
- This is enough for pytest to pick up pytest-asyncio.
-
- Fixtures
- --------
-
- ``event_loop``
- ~~~~~~~~~~~~~~
- Creates and injects a new instance of the default asyncio event loop.
By
- default, the loop will be closed at the end of the test (i.e. the
default
- fixture scope is ``function``).
-
- Note that just using the ``event_loop`` fixture won't make your test
function
- a coroutine. You'll need to interact with the event loop directly,
using methods
- like ``event_loop.run_until_complete``. See the
``pytest.mark.asyncio`` marker
- for treating test functions like coroutines.
-
- Simply using this fixture will not set the generated event loop as the
- default asyncio event loop, or change the asyncio event loop policy in
any way.
- Use ``pytest.mark.asyncio`` for this purpose.
-
- .. code-block:: python
-
- def test_http_client(event_loop):
- url = 'http://httpbin.org/get'
- resp = event_loop.run_until_complete(http_client(url))
- assert b'HTTP/1.1 200 OK' in resp
-
- This fixture can be easily overridden in any of the standard pytest
locations
- (e.g. directly in the test file, or in ``conftest.py``) to use a
non-default
- event loop. This will take effect even if you're using the
- ``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture
directly.
-
- .. code-block:: python
-
- @pytest.yield_fixture()
- def event_loop():
- loop = MyCustomLoop()
- yield loop
- loop.close()
-
- If the ``pytest.mark.asyncio`` marker is applied, a pytest hook will
- ensure the produced loop is set as the default global loop.
- Fixtures depending on the ``event_loop`` fixture can expect the policy
to be properly modified when they run.
-
- ``event_loop_process_pool``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- The ``event_loop_process_pool`` fixture is almost identical to the
- ``event_loop`` fixture, except the created event loop will have a
- ``concurrent.futures.ProcessPoolExecutor`` set as the default executor.
-
- ``unused_tcp_port``
- ~~~~~~~~~~~~~~~~~~~
- Finds and yields a single unused TCP port on the localhost interface.
Useful for
- binding temporary test servers.
-
- ``unused_tcp_port_factory``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- A callable which returns a different unused TCP port each invocation.
Useful
- when several unused TCP ports are required in a test.
-
- .. code-block:: python
-
- def a_test(unused_tcp_port_factory):
- port1, port2 = unused_tcp_port_factory(),
unused_tcp_port_factory()
- ...
-
- Async fixtures
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Asynchronous fixtures are defined just like ordinary pytest fixtures,
except they should be coroutines or asynchronous generators.
-
- .. code-block:: python3
-
- @pytest.fixture
- async def async_gen_fixture():
- await asyncio.sleep(0.1)
- yield 'a value'
-
- @pytest.fixture(scope='module')
- async def async_fixture():
- return await asyncio.sleep(0.1)
-
- All scopes are supported, but if you use a non-function scope you will
need
- to redefine the ``event_loop`` fixture to have the same or broader
scope.
- Async fixtures need the event loop, and so must have the same or
narrower scope
- than the ``event_loop`` fixture.
-
- If you want to do this with Python 3.5, the ``yield`` statement must
be replaced with ``await yield_()`` and the coroutine
- function must be decorated with ``@async_generator``, like so:
-
- .. code-block:: python3
-
- from async_generator import yield_, async_generator
-
- @pytest.fixture
- @async_generator
- async def async_gen_fixture():
- await asyncio.sleep(0.1)
- await yield_('a value')
-
-
- Markers
- -------
-
- ``pytest.mark.asyncio``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Mark your test coroutine with this marker and pytest will execute it
as an
- asyncio task using the event loop provided by the ``event_loop``
fixture. See
- the introductory section for an example.
-
- The event loop used can be overriden by overriding the ``event_loop``
fixture
- (see above).
-
- In order to make your test code a little more concise, the pytest
|pytestmark|_
- feature can be used to mark entire modules or classes with this marker.
- Only test coroutines will be affected (by default, coroutines prefixed
by
- ``test_``), so, for example, fixtures are safe to define.
-
- .. code-block:: python
-
- import asyncio
- import pytest
-
- # All test coroutines will be treated as marked.
- pytestmark = pytest.mark.asyncio
-
- async def test_example(event_loop):
- """No marker!"""
- await asyncio.sleep(0, loop=event_loop)
-
- .. |pytestmark| replace:: ``pytestmark``
- .. _pytestmark:
http://doc.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules
-
- ``pytest.mark.asyncio_process_pool``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- The ``asyncio_process_pool`` marker is almost identical to the
``asyncio``
- marker, except the event loop used will have a
- ``concurrent.futures.ProcessPoolExecutor`` set as the default executor.
-
- Changelog
- ---------
-
- 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>
-
- 0.7.0 (2017-09-08)
- ~~~~~~~~~~~~~~~~~~
- - Python versions pre-3.6 can use the async_generator library for
async fixtures.
- `#62 <https://github.com/pytest-dev/pytest-asyncio/pull/62>`
-
-
- 0.6.0 (2017-05-28)
- ~~~~~~~~~~~~~~~~~~
- - Support for Python versions pre-3.5 has been dropped.
- - ``pytestmark`` now works on both module and class level.
- - The ``forbid_global_loop`` parameter has been removed.
- - Support for async and async gen fixtures has been added.
- `#45 <https://github.com/pytest-dev/pytest-asyncio/pull/45>`_
- - The deprecation warning regarding ``asyncio.async()`` has been fixed.
- `#51 <https://github.com/pytest-dev/pytest-asyncio/pull/51>`_
-
- 0.5.0 (2016-09-07)
- ~~~~~~~~~~~~~~~~~~
- - Introduced a changelog.
- `#31 <https://github.com/pytest-dev/pytest-asyncio/issues/31>`_
- - The ``event_loop`` fixture is again responsible for closing itself.
- This makes the fixture slightly harder to correctly override, but
enables
- other fixtures to depend on it correctly.
- `#30 <https://github.com/pytest-dev/pytest-asyncio/issues/30>`_
- - Deal with the event loop policy by wrapping a special pytest hook,
- ``pytest_fixture_setup``. This allows setting the policy before
fixtures
- dependent on the ``event_loop`` fixture run, thus allowing them to
take
- advantage of the ``forbid_global_loop`` parameter. As a consequence
of this,
- we now depend on pytest 3.0.
- `#29 <https://github.com/pytest-dev/pytest-asyncio/issues/29>`_
-
-
- 0.4.1 (2016-06-01)
- ~~~~~~~~~~~~~~~~~~
- - Fix a bug preventing the propagation of exceptions from the plugin.
- `#25 <https://github.com/pytest-dev/pytest-asyncio/issues/25>`_
-
- 0.4.0 (2016-05-30)
- ~~~~~~~~~~~~~~~~~~
- - Make ``event_loop`` fixtures simpler to override by closing them in
the
- plugin, instead of directly in the fixture.
- `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_
- - Introduce the ``forbid_global_loop`` parameter.
- `#21 <https://github.com/pytest-dev/pytest-asyncio/pull/21>`_
-
- 0.3.0 (2015-12-19)
- ~~~~~~~~~~~~~~~~~~
- - Support for Python 3.5 ``async``/``await`` syntax.
- `#17 <https://github.com/pytest-dev/pytest-asyncio/pull/17>`_
-
- 0.2.0 (2015-08-01)
- ~~~~~~~~~~~~~~~~~~
- - ``unused_tcp_port_factory`` fixture.
- `#10 <https://github.com/pytest-dev/pytest-asyncio/issues/10>`_
-
-
- 0.1.1 (2015-04-23)
- ~~~~~~~~~~~~~~~~~~
- Initial release.
-
-
- Contributing
- ------------
- Contributions are very welcome. Tests can be run with ``tox``, please
ensure
- the coverage at least stays the same before you submit a pull request.
-
-Platform: UNKNOWN
-Classifier: Development Status :: 4 - Beta
-Classifier: Intended Audience :: Developers
-Classifier: License :: OSI Approved :: Apache Software License
-Classifier: Programming Language :: Python :: 3.5
-Classifier: Programming Language :: Python :: 3.6
-Classifier: Topic :: Software Development :: Testing
-Classifier: Framework :: Pytest
-Requires-Python: >= 3.5
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/SOURCES.txt
new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/SOURCES.txt
--- old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/SOURCES.txt
2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/SOURCES.txt
1970-01-01 01:00:00.000000000 +0100
@@ -1,12 +0,0 @@
-LICENSE
-README.rst
-setup.cfg
-setup.py
-pytest_asyncio/__init__.py
-pytest_asyncio/plugin.py
-pytest_asyncio.egg-info/PKG-INFO
-pytest_asyncio.egg-info/SOURCES.txt
-pytest_asyncio.egg-info/dependency_links.txt
-pytest_asyncio.egg-info/entry_points.txt
-pytest_asyncio.egg-info/requires.txt
-pytest_asyncio.egg-info/top_level.txt
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/dependency_links.txt
new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/dependency_links.txt
--- old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/dependency_links.txt
2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/dependency_links.txt
1970-01-01 01:00:00.000000000 +0100
@@ -1 +0,0 @@
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/entry_points.txt
new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/entry_points.txt
--- old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/entry_points.txt
2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/entry_points.txt
1970-01-01 01:00:00.000000000 +0100
@@ -1,3 +0,0 @@
-[pytest11]
-asyncio = pytest_asyncio.plugin
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/requires.txt
new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/requires.txt
--- old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/requires.txt
2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/requires.txt
1970-01-01 01:00:00.000000000 +0100
@@ -1,8 +0,0 @@
-pytest>=3.0.6
-
-[:python_version == "3.5"]
-async_generator>=1.3
-
-[testing]
-coverage
-async_generator>=1.3
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/top_level.txt
new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/top_level.txt
--- old/pytest-asyncio-0.8.0/pytest_asyncio.egg-info/top_level.txt
2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/pytest_asyncio.egg-info/top_level.txt
1970-01-01 01:00:00.000000000 +0100
@@ -1 +0,0 @@
-pytest_asyncio
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/setup.cfg
new/pytest-asyncio-0.9.0/setup.cfg
--- old/pytest-asyncio-0.8.0/setup.cfg 2017-09-23 13:36:35.000000000 +0200
+++ new/pytest-asyncio-0.9.0/setup.cfg 2018-07-28 16:33:29.000000000 +0200
@@ -9,9 +9,5 @@
testpaths = tests
[metadata]
+# ensure LICENSE is included in wheel metadata
license_file = LICENSE
-
-[egg_info]
-tag_build =
-tag_date = 0
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/setup.py
new/pytest-asyncio-0.9.0/setup.py
--- old/pytest-asyncio-0.8.0/setup.py 2017-09-23 13:29:05.000000000 +0200
+++ new/pytest-asyncio-0.9.0/setup.py 2018-07-28 16:33:29.000000000 +0200
@@ -5,9 +5,14 @@
def find_version():
- version_file = Path(__file__).parent.joinpath('pytest_asyncio',
'__init__.py').read_text()
- version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
- version_file, re.M)
+ version_file = (
+ Path(__file__)
+ .parent.joinpath("pytest_asyncio", "__init__.py")
+ .read_text()
+ )
+ version_match = re.search(
+ r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M
+ )
if version_match:
return version_match.group(1)
@@ -15,33 +20,30 @@
setup(
- name='pytest-asyncio',
+ name="pytest-asyncio",
version=find_version(),
packages=find_packages(),
- url='https://github.com/pytest-dev/pytest-asyncio',
- license='Apache 2.0',
- author='Tin Tvrtković',
- author_email='[email protected]',
- description='Pytest support for asyncio.',
- long_description=Path(__file__).parent.joinpath('README.rst').read_text(),
+ url="https://github.com/pytest-dev/pytest-asyncio",
+ license="Apache 2.0",
+ author="Tin Tvrtković",
+ author_email="[email protected]",
+ description="Pytest support for asyncio.",
+ long_description=Path(__file__).parent.joinpath("README.rst").read_text(),
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
+ "Programming Language :: Python :: 3.7",
"Topic :: Software Development :: Testing",
"Framework :: Pytest",
],
- python_requires='>= 3.5',
- install_requires=[
- 'pytest >= 3.0.6',
- ],
+ python_requires=">= 3.5",
+ install_requires=["pytest >= 3.0.6"],
extras_require={
- ':python_version == "3.5"': 'async_generator >= 1.3',
- 'testing': ['coverage', 'async_generator >= 1.3'],
+ ':python_version == "3.5"': "async_generator >= 1.3",
+ "testing": ["coverage", "async_generator >= 1.3"],
},
- entry_points={
- 'pytest11': ['asyncio = pytest_asyncio.plugin'],
- }
+ entry_points={"pytest11": ["asyncio = pytest_asyncio.plugin"]},
)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_fixtures_35.py
new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_fixtures_35.py
--- old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_fixtures_35.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_fixtures_35.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,25 @@
+import asyncio
+import unittest.mock
+
+import pytest
+
+START = object()
+END = object()
+RETVAL = object()
+
+
[email protected]
+def mock():
+ return unittest.mock.Mock(return_value=RETVAL)
+
+
[email protected]
+async def async_fixture(mock):
+ return await asyncio.sleep(0.1, result=mock(START))
+
+
[email protected]
+async def test_async_fixture(async_fixture, mock):
+ assert mock.call_count == 1
+ assert mock.call_args_list[-1] == unittest.mock.call(START)
+ assert async_fixture is RETVAL
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_fixtures_scope.py
new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_fixtures_scope.py
--- old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_fixtures_scope.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_fixtures_scope.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,24 @@
+"""
+We support module-scoped async fixtures, but only if the event loop is
+module-scoped too.
+"""
+import asyncio
+import pytest
+
+
[email protected](scope='module')
+def event_loop():
+ """A module-scoped event loop."""
+ return asyncio.new_event_loop()
+
+
[email protected](scope='module')
+async def async_fixture():
+ await asyncio.sleep(0.1)
+ return 1
+
+
[email protected]
+async def test_async_fixture_scope(async_fixture):
+ assert async_fixture == 1
+ await asyncio.sleep(0.1)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_gen_fixtures_35.py
new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_gen_fixtures_35.py
--- old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_gen_fixtures_35.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_gen_fixtures_35.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,40 @@
+import unittest.mock
+
+import pytest
+from async_generator import yield_, async_generator
+
+START = object()
+END = object()
+RETVAL = object()
+
+
[email protected](scope='module')
+def mock():
+ return unittest.mock.Mock(return_value=RETVAL)
+
+
[email protected]
+@async_generator
+async def async_gen_fixture(mock):
+ try:
+ await yield_(mock(START))
+ except Exception as e:
+ mock(e)
+ else:
+ mock(END)
+
+
[email protected]
+async def test_async_gen_fixture(async_gen_fixture, mock):
+ assert mock.called
+ assert mock.call_args_list[-1] == unittest.mock.call(START)
+ assert async_gen_fixture is RETVAL
+
+
[email protected]
+async def test_async_gen_fixture_finalized(mock):
+ try:
+ assert mock.called
+ assert mock.call_args_list[-1] == unittest.mock.call(END)
+ finally:
+ mock.reset_mock()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_gen_fixtures_36.py
new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_gen_fixtures_36.py
--- old/pytest-asyncio-0.8.0/tests/async_fixtures/test_async_gen_fixtures_36.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/async_fixtures/test_async_gen_fixtures_36.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,39 @@
+import asyncio
+import unittest.mock
+
+import pytest
+
+START = object()
+END = object()
+RETVAL = object()
+
+
[email protected](scope='module')
+def mock():
+ return unittest.mock.Mock(return_value=RETVAL)
+
+
[email protected]
+async def async_gen_fixture(mock):
+ try:
+ yield mock(START)
+ except Exception as e:
+ mock(e)
+ else:
+ mock(END)
+
+
[email protected]
+async def test_async_gen_fixture(async_gen_fixture, mock):
+ assert mock.called
+ assert mock.call_args_list[-1] == unittest.mock.call(START)
+ assert async_gen_fixture is RETVAL
+
+
[email protected]
+async def test_async_gen_fixture_finalized(mock):
+ try:
+ assert mock.called
+ assert mock.call_args_list[-1] == unittest.mock.call(END)
+ finally:
+ mock.reset_mock()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/async_fixtures/test_coroutine_fixtures.py
new/pytest-asyncio-0.9.0/tests/async_fixtures/test_coroutine_fixtures.py
--- old/pytest-asyncio-0.8.0/tests/async_fixtures/test_coroutine_fixtures.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/async_fixtures/test_coroutine_fixtures.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,27 @@
+import asyncio
+import unittest.mock
+
+import pytest
+
+START = object()
+END = object()
+RETVAL = object()
+
+pytestmark = pytest.mark.skip(reason='@asyncio.coroutine fixtures are not
supported yet')
+
+
[email protected]
+def mock():
+ return unittest.mock.Mock(return_value=RETVAL)
+
+
[email protected]
+async def coroutine_fixture(mock):
+ await asyncio.sleep(0.1, result=mock(START))
+
+
[email protected]
+async def test_coroutine_fixture(coroutine_fixture, mock):
+ assert mock.call_count == 1
+ assert mock.call_args_list[-1] == unittest.mock.call(START)
+ assert coroutine_fixture is RETVAL
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/async_fixtures/test_nested_36.py
new/pytest-asyncio-0.9.0/tests/async_fixtures/test_nested_36.py
--- old/pytest-asyncio-0.8.0/tests/async_fixtures/test_nested_36.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/async_fixtures/test_nested_36.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,25 @@
+import asyncio
+import pytest
+
+
[email protected]()
+async def async_inner_fixture():
+ await asyncio.sleep(0.01)
+ print('inner start')
+ yield True
+ print('inner stop')
+
+
[email protected]()
+async def async_fixture_outer(async_inner_fixture, event_loop):
+ await asyncio.sleep(0.01)
+ print('outer start')
+ assert async_inner_fixture is True
+ yield True
+ print('outer stop')
+
+
[email protected]
+async def test_async_fixture(async_fixture_outer):
+ assert async_fixture_outer is True
+ print('test_async_fixture')
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/tests/conftest.py
new/pytest-asyncio-0.9.0/tests/conftest.py
--- old/pytest-asyncio-0.8.0/tests/conftest.py 1970-01-01 01:00:00.000000000
+0100
+++ new/pytest-asyncio-0.9.0/tests/conftest.py 2018-07-28 16:33:29.000000000
+0200
@@ -0,0 +1,28 @@
+import asyncio
+import sys
+
+import pytest
+
+collect_ignore = []
+if sys.version_info[:2] < (3, 6):
+ collect_ignore.append("async_fixtures/test_async_gen_fixtures_36.py")
+ collect_ignore.append("async_fixtures/test_nested_36.py")
+
+
[email protected]_fixture()
+def dependent_fixture(event_loop):
+ """A fixture dependent on the event_loop fixture, doing some cleanup."""
+ counter = 0
+
+ async def just_a_sleep():
+ """Just sleep a little while."""
+ nonlocal event_loop
+ await asyncio.sleep(0.1, loop=event_loop)
+ nonlocal counter
+ counter += 1
+
+ event_loop.run_until_complete(just_a_sleep())
+ yield
+ event_loop.run_until_complete(just_a_sleep())
+
+ assert counter == 2
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/markers/test_class_marker_35.py
new/pytest-asyncio-0.9.0/tests/markers/test_class_marker_35.py
--- old/pytest-asyncio-0.8.0/tests/markers/test_class_marker_35.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/markers/test_class_marker_35.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,23 @@
+"""Test if pytestmark works when defined on a class."""
+import asyncio
+import pytest
+
+
+class TestPyTestMark:
+ pytestmark = pytest.mark.asyncio
+
+ async def test_is_asyncio(self, event_loop, sample_fixture):
+ assert asyncio.get_event_loop()
+ counter = 1
+
+ async def inc():
+ nonlocal counter
+ counter += 1
+ await asyncio.sleep(0)
+ await asyncio.ensure_future(inc())
+ assert counter == 2
+
+
[email protected]
+def sample_fixture():
+ return None
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/markers/test_module_marker_35.py
new/pytest-asyncio-0.9.0/tests/markers/test_module_marker_35.py
--- old/pytest-asyncio-0.8.0/tests/markers/test_module_marker_35.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/markers/test_module_marker_35.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,37 @@
+"""Test if pytestmark works when defined in a module."""
+import asyncio
+
+import pytest
+
+pytestmark = pytest.mark.asyncio
+
+
+class TestPyTestMark:
+ async def test_is_asyncio(self, event_loop, sample_fixture):
+ assert asyncio.get_event_loop()
+
+ counter = 1
+
+ async def inc():
+ nonlocal counter
+ counter += 1
+ await asyncio.sleep(0)
+
+ await asyncio.ensure_future(inc())
+ assert counter == 2
+
+
+async def test_is_asyncio(event_loop, sample_fixture):
+ assert asyncio.get_event_loop()
+ counter = 1
+ async def inc():
+ nonlocal counter
+ counter += 1
+ await asyncio.sleep(0)
+ await asyncio.ensure_future(inc())
+ assert counter == 2
+
+
[email protected]
+def sample_fixture():
+ return None
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/tests/multiloop/conftest.py
new/pytest-asyncio-0.9.0/tests/multiloop/conftest.py
--- old/pytest-asyncio-0.8.0/tests/multiloop/conftest.py 1970-01-01
01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/multiloop/conftest.py 2018-07-28
16:33:29.000000000 +0200
@@ -0,0 +1,16 @@
+import asyncio
+
+import pytest
+
+
+class CustomSelectorLoop(asyncio.SelectorEventLoop):
+ """A subclass with no overrides, just to test for presence."""
+ pass
+
+
[email protected]_fixture()
+def event_loop():
+ """Create an instance of the default event loop for each test case."""
+ loop = CustomSelectorLoop()
+ yield loop
+ loop.close()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/multiloop/test_alternative_loops.py
new/pytest-asyncio-0.9.0/tests/multiloop/test_alternative_loops.py
--- old/pytest-asyncio-0.8.0/tests/multiloop/test_alternative_loops.py
1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/multiloop/test_alternative_loops.py
2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,16 @@
+"""Unit tests for overriding the event loop."""
+import asyncio
+
+import pytest
+
+
[email protected]
+async def test_for_custom_loop():
+ """This test should be executed using the custom loop."""
+ await asyncio.sleep(0.01)
+ assert type(asyncio.get_event_loop()).__name__ == "CustomSelectorLoop"
+
+
[email protected]
+async def test_dependent_fixture(dependent_fixture):
+ await asyncio.sleep(0.1)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/test_dependent_fixtures.py
new/pytest-asyncio-0.9.0/tests/test_dependent_fixtures.py
--- old/pytest-asyncio-0.8.0/tests/test_dependent_fixtures.py 1970-01-01
01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/test_dependent_fixtures.py 2018-07-28
16:33:29.000000000 +0200
@@ -0,0 +1,8 @@
+import asyncio
+import pytest
+
+
[email protected]
+async def test_dependent_fixture(dependent_fixture):
+ """Test a dependent fixture."""
+ await asyncio.sleep(0.1)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pytest-asyncio-0.8.0/tests/test_event_loop_scope_35.py
new/pytest-asyncio-0.9.0/tests/test_event_loop_scope_35.py
--- old/pytest-asyncio-0.8.0/tests/test_event_loop_scope_35.py 1970-01-01
01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/test_event_loop_scope_35.py 2018-07-28
16:33:29.000000000 +0200
@@ -0,0 +1,21 @@
+"""Test the event loop fixture is properly disposed of.
+
+These tests need to be run together.
+"""
+import asyncio
+import pytest
+
+
+def test_1():
+ loop = asyncio.get_event_loop()
+ assert not loop.is_closed()
+
+
[email protected]
+async def test_2():
+ pass
+
+
+def test_3():
+ loop = asyncio.get_event_loop()
+ assert not loop.is_closed()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/tests/test_simple.py
new/pytest-asyncio-0.9.0/tests/test_simple.py
--- old/pytest-asyncio-0.8.0/tests/test_simple.py 1970-01-01
01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/test_simple.py 2018-07-28
16:33:29.000000000 +0200
@@ -0,0 +1,136 @@
+"""Quick'n'dirty unit tests for provided fixtures and markers."""
+import asyncio
+import os
+import pytest
+
+import pytest_asyncio.plugin
+
+
+async def async_coro(loop=None):
+ """A very simple coroutine."""
+ await asyncio.sleep(0, loop=loop)
+ return 'ok'
+
+
+def test_event_loop_fixture(event_loop):
+ """Test the injection of the event_loop fixture."""
+ assert event_loop
+ ret = event_loop.run_until_complete(async_coro(event_loop))
+ assert ret == 'ok'
+
+
[email protected]
+def test_asyncio_marker():
+ """Test the asyncio pytest marker."""
+ yield # sleep(0)
+
+
[email protected](reason='need a failure', strict=True)
[email protected]
+def test_asyncio_marker_fail():
+ assert False
+
+
[email protected]
+def test_asyncio_marker_with_default_param(a_param=None):
+ """Test the asyncio pytest marker."""
+ yield # sleep(0)
+
+
[email protected]
+async def test_unused_port_fixture(unused_tcp_port, event_loop):
+ """Test the unused TCP port fixture."""
+
+ async def closer(_, writer):
+ writer.close()
+
+ server1 = await asyncio.start_server(closer, host='localhost',
+ port=unused_tcp_port,
+ loop=event_loop)
+
+ with pytest.raises(IOError):
+ await asyncio.start_server(closer, host='localhost',
+ port=unused_tcp_port,
+ loop=event_loop)
+
+ server1.close()
+ await server1.wait_closed()
+
+
[email protected]
+async def test_unused_port_factory_fixture(unused_tcp_port_factory,
event_loop):
+ """Test the unused TCP port factory fixture."""
+
+ async def closer(_, writer):
+ writer.close()
+
+ port1, port2, port3 = (unused_tcp_port_factory(),
unused_tcp_port_factory(),
+ unused_tcp_port_factory())
+
+ server1 = await asyncio.start_server(closer, host='localhost',
+ port=port1,
+ loop=event_loop)
+ server2 = await asyncio.start_server(closer, host='localhost',
+ port=port2,
+ loop=event_loop)
+ server3 = await asyncio.start_server(closer, host='localhost',
+ port=port3,
+ loop=event_loop)
+
+ for port in port1, port2, port3:
+ with pytest.raises(IOError):
+ await asyncio.start_server(closer, host='localhost',
+ port=port,
+ loop=event_loop)
+
+ server1.close()
+ await server1.wait_closed()
+ server2.close()
+ await server2.wait_closed()
+ server3.close()
+ await server3.wait_closed()
+
+
+def test_unused_port_factory_duplicate(unused_tcp_port_factory, monkeypatch):
+ """Test correct avoidance of duplicate ports."""
+ counter = 0
+
+ def mock_unused_tcp_port():
+ """Force some duplicate ports."""
+ nonlocal counter
+ counter += 1
+ if counter < 5:
+ return 10000
+ else:
+ return 10000 + counter
+
+ monkeypatch.setattr(pytest_asyncio.plugin, 'unused_tcp_port',
+ mock_unused_tcp_port)
+
+ assert unused_tcp_port_factory() == 10000
+ assert unused_tcp_port_factory() > 10000
+
+
+class Test:
+ """Test that asyncio marked functions work in test methods."""
+
+ @pytest.mark.asyncio
+ async def test_asyncio_marker_method(self, event_loop):
+ """Test the asyncio pytest marker in a Test class."""
+ ret = await async_coro(event_loop)
+ assert ret == 'ok'
+
+
+class TestUnexistingLoop:
+ @pytest.fixture
+ def remove_loop(self):
+ old_loop = asyncio.get_event_loop()
+ asyncio.set_event_loop(None)
+ yield
+ asyncio.set_event_loop(old_loop)
+
+ @pytest.mark.asyncio
+ async def test_asyncio_marker_without_loop(self, remove_loop):
+ """Test the asyncio pytest marker in a Test class."""
+ ret = await async_coro()
+ assert ret == 'ok'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/tests/test_simple_35.py
new/pytest-asyncio-0.9.0/tests/test_simple_35.py
--- old/pytest-asyncio-0.8.0/tests/test_simple_35.py 1970-01-01
01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/test_simple_35.py 2018-07-28
16:33:29.000000000 +0200
@@ -0,0 +1,88 @@
+"""Quick'n'dirty unit tests using async and await syntax."""
+import asyncio
+
+import pytest
+
+
[email protected]
+async def async_coro(loop):
+ await asyncio.sleep(0, loop=loop)
+ return 'ok'
+
+
[email protected]
+async def test_asyncio_marker():
+ """Test the asyncio pytest marker."""
+
+
[email protected]
+async def test_asyncio_marker_with_default_param(a_param=None):
+ """Test the asyncio pytest marker."""
+
+
[email protected]
+async def test_unused_port_fixture(unused_tcp_port, event_loop):
+ """Test the unused TCP port fixture."""
+ async def closer(_, writer):
+ writer.close()
+
+ server1 = await asyncio.start_server(closer, host='localhost',
+ port=unused_tcp_port,
+ loop=event_loop)
+
+ server1.close()
+ await server1.wait_closed()
+
+
+def test_unused_port_factory_fixture(unused_tcp_port_factory, event_loop):
+ """Test the unused TCP port factory fixture."""
+
+ async def closer(_, writer):
+ writer.close()
+
+ port1, port2, port3 = (unused_tcp_port_factory(),
unused_tcp_port_factory(),
+ unused_tcp_port_factory())
+
+ async def run_test():
+ server1 = await asyncio.start_server(closer, host='localhost',
+ port=port1,
+ loop=event_loop)
+ server2 = await asyncio.start_server(closer, host='localhost',
+ port=port2,
+ loop=event_loop)
+ server3 = await asyncio.start_server(closer, host='localhost',
+ port=port3,
+ loop=event_loop)
+
+ for port in port1, port2, port3:
+ with pytest.raises(IOError):
+ await asyncio.start_server(closer, host='localhost',
+ port=port,
+ loop=event_loop)
+
+ server1.close()
+ await server1.wait_closed()
+ server2.close()
+ await server2.wait_closed()
+ server3.close()
+ await server3.wait_closed()
+
+ event_loop.run_until_complete(run_test())
+
+ event_loop.stop()
+ event_loop.close()
+
+
+class Test:
+ """Test that asyncio marked functions work in test methods."""
+
+ @pytest.mark.asyncio
+ async def test_asyncio_marker_method(self, event_loop):
+ """Test the asyncio pytest marker in a Test class."""
+ ret = await async_coro(event_loop)
+ assert ret == 'ok'
+
+
+def test_async_close_loop(event_loop):
+ event_loop.close()
+ return 'ok'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/tests/test_subprocess.py
new/pytest-asyncio-0.9.0/tests/test_subprocess.py
--- old/pytest-asyncio-0.8.0/tests/test_subprocess.py 1970-01-01
01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tests/test_subprocess.py 2018-07-28
16:33:29.000000000 +0200
@@ -0,0 +1,24 @@
+"""Tests for using subprocesses in tests."""
+import sys
+import asyncio
+import asyncio.subprocess
+
+import pytest
+
+
[email protected](forbid_global_loop=False)
+async def test_subprocess(event_loop):
+ """Starting a subprocess should be possible."""
+ proc = await asyncio.subprocess.create_subprocess_exec(
+ sys.executable, '--version', stdout=asyncio.subprocess.PIPE,
+ loop=event_loop)
+ await proc.communicate()
+
+
[email protected](forbid_global_loop=True)
+async def test_subprocess_forbid(event_loop):
+ """Starting a subprocess should be possible."""
+ proc = await asyncio.subprocess.create_subprocess_exec(
+ sys.executable, '--version', stdout=asyncio.subprocess.PIPE,
+ loop=event_loop)
+ await proc.communicate()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pytest-asyncio-0.8.0/tox.ini
new/pytest-asyncio-0.9.0/tox.ini
--- old/pytest-asyncio-0.8.0/tox.ini 1970-01-01 01:00:00.000000000 +0100
+++ new/pytest-asyncio-0.9.0/tox.ini 2018-07-28 16:33:29.000000000 +0200
@@ -0,0 +1,14 @@
+[tox]
+envlist = py35, py36, py37
+minversion = 2.5.0
+
+[testenv]
+extras = testing
+commands = coverage run -m pytest {posargs}
+
+[testenv:coverage-report]
+deps = coverage
+skip_install = true
+commands =
+ coverage combine
+ coverage report