Skip to content

Commit

Permalink
Merge pull request #14 from kwarunek/bugfix/#12_invoke_specific_test_…
Browse files Browse the repository at this point in the history
…case_from_command_line

bugfix/#12_invoke_specific_test_case_from_command_line
  • Loading branch information
kwarunek committed May 27, 2020
2 parents 78e3aff + b91bfe7 commit 0b37628
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The `aiounittest` is a helper library to ease of your pain (and boilerplate), wh
* asynchronous code, it supports syntax with :code:`async`/:code:`await` (Python 3.5+) and :code:`asyncio.coroutine`/:code:`yield from` (Python 3.4)


In the Python 3.8 and above (https://docs.python.org/3/whatsnew/3.8.html#unittest) consider to use the `unittest.IsolatedAsyncioTestCase` (https://docs.python.org/3/library/unittest.html#unittest.IsolatedAsyncioTestCase).


Installation
============

Expand Down
36 changes: 17 additions & 19 deletions aiounittest/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import functools
import wrapt


def futurized(o):
Expand Down Expand Up @@ -125,26 +126,23 @@ def get_brand_new_default_event_loop():
asyncio.set_event_loop(_loop)
return _loop

def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
nonlocal loop
use_default_event_loop = loop is None
@wrapt.decorator
def decorator(wrapped, instance, args, kwargs):
nonlocal loop
use_default_event_loop = loop is None
if use_default_event_loop:
loop = get_brand_new_default_event_loop()
try:
ret = wrapped(*args, **kwargs)
future = asyncio.ensure_future(ret, loop=loop)
return loop.run_until_complete(future)
finally:
if use_default_event_loop:
loop = get_brand_new_default_event_loop()
try:
ret = f(*args, **kwargs)
future = asyncio.ensure_future(ret, loop=loop)
return loop.run_until_complete(future)
finally:
if use_default_event_loop:
# clean up
loop.close()
del loop
# again set a new (unstopped) event loop
get_brand_new_default_event_loop()

return wrapper
# clean up
loop.close()
del loop
# again set a new (unstopped) event loop
get_brand_new_default_event_loop()

if func is None:
return decorator
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
# built documents.
#
# The short X.Y version.
version = u'1.3.1'
version = u'1.4.0'
# The full version, including alpha/beta/rc tags.
release = u'1.3.1'
release = u'1.4.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 6 additions & 0 deletions docs/info.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
What? Why? Next?
================


Why Not?
--------

In the Python 3.8 and above (https://docs.python.org/3/whatsnew/3.8.html#unittest) consider to use the `unittest.IsolatedAsyncioTestCase` (https://docs.python.org/3/library/unittest.html#unittest.IsolatedAsyncioTestCase).

What?
-----

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setup(
name='aiounittest',
packages=['aiounittest'],
version='1.3.1',
version='1.4.0',
author='Krzysztof Warunek',
author_email='krzysztof@warunek.net',
description='Test asyncio code more easily.',
Expand All @@ -18,6 +18,7 @@
long_description=open('README.rst').read(),
tests_require=['nose', 'coverage'],
package_data={'aiounittest': ['py.typed']},
install_requires=['wrapt'],
license="MIT",
classifiers=[
'License :: OSI Approved :: MIT License',
Expand Down
8 changes: 8 additions & 0 deletions tests/test_unitest_module_invocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
from unittest.main import main


def test_specific_test():
sys.argv = ['TEST']
sys.argv.append('test_asynctestcase.TestAsyncCase.test_await_async_add')
a = main(module=None, exit=False)

0 comments on commit 0b37628

Please sign in to comment.