Skip to content

Commit

Permalink
Fixing PR remarks. Made pytest.mark.curio completely isolated from co…
Browse files Browse the repository at this point in the history
…nftest.py (for now it's easier to add new backend with custom marks) (#94)
  • Loading branch information
cdeler committed Aug 31, 2020
1 parent bcfb950 commit 46bdc25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@

from httpcore._types import URL

from .marks.curio import kernel # noqa: F401
from .marks.curio import pytest_pycollect_makeitem # noqa: F401
from .marks.curio import pytest_pyfunc_call # noqa: F401
from .marks.curio import curio_kernel_fixture # noqa: F401
from .marks.curio import curio_pytest_pycollect_makeitem, curio_pytest_pyfunc_call

PROXY_HOST = "127.0.0.1"
PROXY_PORT = 8080


@pytest.mark.tryfirst
def pytest_pycollect_makeitem(collector, name, obj):
curio_pytest_pycollect_makeitem(collector, name, obj)


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
yield from curio_pytest_pyfunc_call(pyfuncitem)


@pytest.fixture(
params=[
pytest.param("asyncio", marks=pytest.mark.asyncio),
Expand Down
6 changes: 3 additions & 3 deletions tests/marks/curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _is_coroutine(obj):


@pytest.mark.tryfirst
def pytest_pycollect_makeitem(collector, name, obj):
def curio_pytest_pycollect_makeitem(collector, name, obj):
"""A pytest hook to collect coroutines in a test module."""
if collector.funcnamefilter(name) and _is_coroutine(obj):
item = pytest.Function.from_parent(collector, name=name)
Expand All @@ -23,7 +23,7 @@ def pytest_pycollect_makeitem(collector, name, obj):


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
def curio_pytest_pyfunc_call(pyfuncitem):
"""Run curio marked test functions in a Curio kernel instead of a normal function call.
"""
if pyfuncitem.get_closest_marker("curio"):
Expand All @@ -44,7 +44,7 @@ def inner(**kwargs):

# Fixture for explicitly running in Kernel instance.
@pytest.fixture(scope="session")
def kernel(request):
def curio_kernel_fixture(request):
"""Provide a Curio Kernel object for running co-routines."""
k = curio.Kernel(debug=[curio.debug.longblock, curio.debug.logcrash])
m = curio.monitor.Monitor(k)
Expand Down

0 comments on commit 46bdc25

Please sign in to comment.