Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Laughlin committed Apr 18, 2020
1 parent 2a62610 commit 4c93d4d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 50 deletions.
10 changes: 2 additions & 8 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ def pytest_fixture_setup(fixturedef, request):
fixturedef.addfinalizer(lambda: policy.set_event_loop(old_loop))
return

if 'context' in request.fixturenames:
if fixturedef.argname != 'context' and fixturedef.scope == 'function':
context = request.getfixturevalue('context')
else:
context = None

if isasyncgenfunction(fixturedef.func):
# This is an async generator function. Wrap it accordingly.
generator = fixturedef.func
Expand Down Expand Up @@ -204,12 +198,12 @@ def __init__(self, coro, *, loop=None, name=None, context=None):


@pytest.fixture
def context(request):
def context(event_loop, request):
"""Create an empty context for the async test case and it's async fixtures."""
context = Context()
def taskfactory(loop, coro):
return Task(coro, loop=loop, context=context)
asyncio.get_event_loop().set_task_factory(taskfactory)
event_loop.set_task_factory(taskfactory)
return context


Expand Down
21 changes: 21 additions & 0 deletions tests/test_contextvars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Quick'n'dirty unit tests for provided fixtures and markers."""
import asyncio
import pytest

import pytest_asyncio.plugin

from contextvars import ContextVar


ctxvar = ContextVar('ctxvar')


@pytest.fixture
async def set_some_context(context):
ctxvar.set('quarantine is fun')


@pytest.mark.asyncio
async def test_test(set_some_context):
# print ("Context in test:", list(context.items()))
assert ctxvar.get() == 'quarantine is fun'
42 changes: 0 additions & 42 deletions tests/test_hypothesis_integration.py

This file was deleted.

0 comments on commit 4c93d4d

Please sign in to comment.