File tree Expand file tree Collapse file tree 1 file changed +0
-51
lines changed Expand file tree Collapse file tree 1 file changed +0
-51
lines changed Original file line number Diff line number Diff line change 55from pytest import Pytester
66
77
8- def test_event_loop_fixture_respects_event_loop_policy (pytester : Pytester ):
9- pytester .makeini ("[pytest]\n asyncio_default_fixture_loop_scope = function" )
10- pytester .makeconftest (
11- dedent (
12- """\
13- '''Defines and sets a custom event loop policy'''
14- import asyncio
15- from asyncio import DefaultEventLoopPolicy, SelectorEventLoop
16-
17- class TestEventLoop(SelectorEventLoop):
18- pass
19-
20- class TestEventLoopPolicy(DefaultEventLoopPolicy):
21- def new_event_loop(self):
22- return TestEventLoop()
23-
24- # This statement represents a code which sets a custom event loop policy
25- asyncio.set_event_loop_policy(TestEventLoopPolicy())
26- """
27- )
28- )
29- pytester .makepyfile (
30- dedent (
31- """\
32- '''Tests that any externally provided event loop policy remains unaltered'''
33- import asyncio
34-
35- import pytest
36-
37-
38- @pytest.mark.asyncio
39- async def test_uses_loop_provided_by_custom_policy():
40- '''Asserts that test cases use the event loop
41- provided by the custom event loop policy'''
42- assert type(asyncio.get_event_loop()).__name__ == "TestEventLoop"
43-
44-
45- @pytest.mark.asyncio
46- async def test_custom_policy_is_not_overwritten():
47- '''
48- Asserts that any custom event loop policy stays the same
49- across test cases.
50- '''
51- assert type(asyncio.get_event_loop()).__name__ == "TestEventLoop"
52- """
53- )
54- )
55- result = pytester .runpytest ("--asyncio-mode=strict" )
56- result .assert_outcomes (passed = 2 )
57-
58-
598def test_event_loop_fixture_handles_unclosed_async_gen (
609 pytester : Pytester ,
6110):
You can’t perform that action at this time.
0 commit comments