Skip to content

Commit

Permalink
Test that from_thread.run(_sync)? sets sniffio
Browse files Browse the repository at this point in the history
  • Loading branch information
gschaffner committed Jan 13, 2023
1 parent 0cbb84b commit bc3cc49
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_from_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any, AsyncGenerator, NoReturn, TypeVar

import pytest
import sniffio
from _pytest.logging import LogCaptureFixture

from anyio import (
Expand Down Expand Up @@ -145,6 +146,17 @@ def worker() -> int:

assert await to_thread.run_sync(worker) == 6

async def test_sniffio_overridden(self, anyio_backend_name: str) -> None:
async def async_func() -> str:
await checkpoint()
return sniffio.current_async_library()

def worker() -> str:
sniffio.current_async_library_cvar.set("something invalid for async_func")
return from_thread.run(async_func)

assert await to_thread.run_sync(worker) == anyio_backend_name


class TestRunSyncFromThread:
def test_run_sync_from_unclaimed_thread(self) -> None:
Expand All @@ -163,6 +175,13 @@ def worker() -> int:

assert await to_thread.run_sync(worker) == 6

async def test_sniffio_overridden(self, anyio_backend_name: str) -> None:
def worker() -> str:
sniffio.current_async_library_cvar.set("something invalid for async_func")
return from_thread.run_sync(sniffio.current_async_library)

assert await to_thread.run_sync(worker) == anyio_backend_name


class TestBlockingPortal:
class AsyncCM:
Expand Down

0 comments on commit bc3cc49

Please sign in to comment.