Skip to content

Commit

Permalink
Add async flag when wrapping async function (#111) (#112)
Browse files Browse the repository at this point in the history
* Add async flag when wrapping async function

* Pin Ubuntu version

* Pin Ubuntu version to 18.04

* Update Python action version

* Drop support for Python 2.7

* Fix async tests for python 3.7

---------

Co-authored-by: Vsevolod Glumov <[email protected]>
  • Loading branch information
soldag and wswld authored Nov 8, 2023
1 parent 2125da1 commit f96c225
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
timeout-minutes: 5
strategy:
matrix:
python-version: [2.7, 3.6, 3.7, 3.8, 3.9, '3.10']
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
12 changes: 9 additions & 3 deletions ddt.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,15 @@ def feed_data(func, new_name, test_data_docstring, *args, **kwargs):
This internal method decorator feeds the test data item to the test.
"""
@wraps(func)
def wrapper(self):
return func(self, *args, **kwargs)
if inspect.iscoroutinefunction(func):
@wraps(func)
async def wrapper(self):
return await func(self, *args, **kwargs)
else:
@wraps(func)
def wrapper(self):
return func(self, *args, **kwargs)

wrapper.__name__ = new_name
wrapper.__wrapped__ = func
# set docstring if exists
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiounittest
codecov
coverage
flake8
Expand Down
11 changes: 11 additions & 0 deletions test/test_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import aiounittest

from ddt import ddt, data
from test.mycode import larger_than_two


@ddt
class TestAsync(aiounittest.AsyncTestCase):
@data(3, 4, 12, 23)
async def test_larger_than_two(self, value):
self.assertTrue(larger_than_two(value))
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ deps =
pytest
pytest-cov
coverage
aiounittest
flake8
six>=1.4.0
PyYAML
Expand Down

0 comments on commit f96c225

Please sign in to comment.