Skip to content
Draft
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
18 changes: 18 additions & 0 deletions tests/test_cached.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import contextlib
import contextvars
from unittest.mock import AsyncMock, MagicMock, call

import pytest
Expand Down Expand Up @@ -68,6 +69,23 @@
assert await decorated_fn("foo") == ("foo",)
assert await decorated_fn("foo", bar="baz") == ("foo", ("bar", "baz"))

async def test_context_var_passed(self):
var = contextvars.ContextVar("var")
var.set("test")

def read_contextvar():
return var.get()

async def example():
var.set("example")
return read_contextvar()

decorated_fn = cachetools_async.cached({})(example)

actual = await decorated_fn()
assert actual == "example"
assert var.get() == "test"

async def test_multiple_calls(self):
mock = AsyncMock()

Expand Down
Loading