Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support trio_run = trio_asyncio ini option #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ such as via :ref:`guest mode <trio:guest-mode>`, it can be used with
pytest-trio as well. Setting ``trio_run`` in the pytest configuration
makes your choice the global default for both tests explicitly marked
with ``@pytest.mark.trio`` and those automatically marked by Trio mode.
``trio_run`` presently supports ``trio`` and ``qtrio``.
``trio_run`` presently supports ``trio``, ``qtrio``, and
``trio_asyncio``.

.. code-block:: ini

Expand Down
25 changes: 25 additions & 0 deletions pytest_trio/_tests/test_trio_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def run(*args, **kwargs):
"""


# Fake trio_asyncio module.
trio_asyncio_text = qtrio_text


def test_trio_mode_and_qtrio_run_configuration(testdir):
testdir.makefile(".ini", pytest="[pytest]\ntrio_mode = true\ntrio_run = qtrio\n")

Expand Down Expand Up @@ -116,6 +120,27 @@ async def test_fake_qtrio_used():
result.assert_outcomes(passed=1)


def test_trio_asyncio_just_run_configuration(testdir):
testdir.makefile(".ini", pytest="[pytest]\ntrio_run = trio_asyncio\n")

testdir.makepyfile(trio_asyncio=trio_asyncio_text)

test_text = """
import pytest
import trio_asyncio
import trio

@pytest.mark.trio
async def test_fake_trio_asyncio_used():
await trio.sleep(0)
assert trio_asyncio.fake_used
"""
testdir.makepyfile(test_text)

result = testdir.runpytest()
result.assert_outcomes(passed=1)


def test_invalid_trio_run_fails(testdir):
run_name = "invalid_trio_run"

Expand Down
8 changes: 6 additions & 2 deletions pytest_trio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def pytest_addoption(parser):
)
parser.addini(
"trio_run",
"what runner should pytest-trio use? [trio, qtrio]",
"what runner should pytest-trio use? [trio, qtrio, trio_asyncio]",
default="trio",
)

Expand Down Expand Up @@ -515,10 +515,14 @@ def choose_run(config):
import qtrio

run = qtrio.run
elif run_string == "trio_asyncio":
import trio_asyncio

run = trio_asyncio.run
else:
raise ValueError(
f"{run_string!r} not valid for 'trio_run' config."
+ " Must be one of: trio, qtrio"
+ " Must be one of: trio, qtrio, trio_asyncio"
)

return run
Expand Down
Loading