-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from sashgorokhov/feature/async_fixtures
Add async fixture support (#41)
- Loading branch information
Showing
10 changed files
with
180 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
language: python | ||
python: 3.5 | ||
|
||
env: | ||
- TOX_ENV=py33 | ||
- TOX_ENV=py34 | ||
- TOX_ENV=py35 | ||
python: | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
|
||
install: | ||
- pip install tox | ||
- pip install tox tox-travis | ||
|
||
script: tox -e $TOX_ENV | ||
script: tox | ||
|
||
after_success: | ||
- pip install coveralls && cd tests && coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
"""The main point for importing pytest-asyncio items.""" | ||
__version__ = '0.5.0' | ||
|
||
from .plugin import async_fixture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import asyncio | ||
import unittest.mock | ||
|
||
import pytest | ||
|
||
START = object() | ||
END = object() | ||
RETVAL = object() | ||
|
||
|
||
@pytest.fixture | ||
def mock(): | ||
return unittest.mock.Mock(return_value=RETVAL) | ||
|
||
|
||
@pytest.fixture | ||
async def async_fixture(mock): | ||
return await asyncio.sleep(0.1, result=mock(START)) | ||
|
||
|
||
@pytest.mark.asyncio | ||
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 | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
async def async_fixture_module_cope(): | ||
return await asyncio.sleep(0.1, result=RETVAL) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_async_fixture_module_cope1(async_fixture_module_cope): | ||
assert async_fixture_module_cope is RETVAL | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.xfail(reason='Only function scoped async fixtures are supported') | ||
async def test_async_fixture_module_cope2(async_fixture_module_cope): | ||
assert async_fixture_module_cope is RETVAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import asyncio | ||
import unittest.mock | ||
|
||
import pytest | ||
|
||
START = object() | ||
END = object() | ||
RETVAL = object() | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def mock(): | ||
return unittest.mock.Mock(return_value=RETVAL) | ||
|
||
|
||
@pytest.fixture | ||
async def async_gen_fixture(mock): | ||
try: | ||
yield mock(START) | ||
except Exception as e: | ||
mock(e) | ||
else: | ||
mock(END) | ||
|
||
|
||
@pytest.mark.asyncio | ||
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 | ||
|
||
|
||
@pytest.mark.asyncio | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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') | ||
|
||
|
||
@pytest.fixture | ||
def mock(): | ||
return unittest.mock.Mock(return_value=RETVAL) | ||
|
||
|
||
@pytest.fixture | ||
@asyncio.coroutine | ||
def coroutine_fixture(mock): | ||
yield from asyncio.sleep(0.1, result=mock(START)) | ||
|
||
|
||
@pytest.mark.asyncio | ||
@asyncio.coroutine | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.