Debian Codegraph @

tests/async_fixtures/test_async_fixtures.py

raw
1 from __future__ import annotations
2
3 import asyncio
4 import unittest.mock
5
6 import pytest
7
8 START = object()
9 END = object()
10 RETVAL = object()
11
12
13 @pytest.fixture
14 def mock():
15 return unittest.mock.Mock(return_value=RETVAL)
16
17
18 @pytest.fixture
19 async def async_fixture(mock):
20 return await asyncio.sleep(0.1, result=mock(START))
21
22
23 @pytest.mark.asyncio
24 async def test_async_fixture(async_fixture, mock):
25 assert mock.call_count == 1
26 assert mock.call_args_list[-1] == unittest.mock.call(START)
27 assert async_fixture is RETVAL
28
29
30 class TestAsyncFixtureMethod:
31 is_same_instance = False
32
33 @pytest.fixture(autouse=True)
34 async def async_fixture_method(self):
35 self.is_same_instance = True
36
37 @pytest.mark.asyncio
38 async def test_async_fixture_method(self):
39 assert self.is_same_instance