Skip to content

Commit

Permalink
Merge pull request #352 from nolar/fix-asyncio-tests
Browse files Browse the repository at this point in the history
Fix async tests with no explicit `event_loop` usage/declaration
  • Loading branch information
nolar authored Apr 28, 2020
2 parents 47b4424 + 67f63a4 commit 8439252
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# Everything needed to develop (test, debug) the framework.
coverage<5.0 # manual enforcement where pip fails, see #272.
pytest-aiohttp
pytest-asyncio
pytest-mock>=1.11.1
pytest-asyncio==0.10.0 # until fixed: https://github.com/pytest-dev/pytest-asyncio/issues/154
pytest-mock
pytest-cov
pytest
pytest==5.3.5 # until fixed: https://github.com/pytest-dev/pytest-asyncio/issues/154
aresponses
asynctest
freezegun
Expand Down
14 changes: 9 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ def pytest_addoption(parser):
parser.addoption("--with-e2e", action="store_true", help="Include end-to-end tests.")


# Make all tests in this directory and below asyncio-compatible by default.
# Due to how pytest-async checks for these markers, they should be added as early as possible.
@pytest.hookimpl(hookwrapper=True)
def pytest_pycollect_makeitem(collector, name, obj):
if collector.funcnamefilter(name) and asyncio.iscoroutinefunction(obj):
pytest.mark.asyncio(obj)
yield


# This logic is not applied if pytest is started explicitly on ./examples/.
# In that case, regular pytest behaviour applies -- this is intended.
def pytest_collection_modifyitems(config, items):

# Make all tests in this directory and below asyncio-compatible by default.
for item in items:
if asyncio.iscoroutinefunction(item.function):
item.add_marker('asyncio')

# Put all e2e tests to the end, as they are assumed to be slow.
def _is_e2e(item):
path = item.location[0]
Expand Down

0 comments on commit 8439252

Please sign in to comment.