File tree 1 file changed +36
-21
lines changed
1 file changed +36
-21
lines changed Original file line number Diff line number Diff line change 1
- import asyncio
1
+ from textwrap import dedent
2
2
3
- import pytest
3
+ from pytest import Pytester
4
4
5
- TESTS_COUNT = 0
6
5
6
+ def test_event_loop_parametrization (pytester : Pytester ):
7
+ pytester .makepyfile (
8
+ dedent (
9
+ """\
10
+ import asyncio
7
11
8
- def teardown_module ():
9
- # parametrized 2 * 2 times: 2 for 'event_loop' and 2 for 'fix'
10
- assert TESTS_COUNT == 4
12
+ import pytest
13
+ import pytest_asyncio
11
14
15
+ TESTS_COUNT = 0
12
16
13
- @pytest .fixture (scope = "module" , params = [1 , 2 ])
14
- def event_loop (request ):
15
- request .param
16
- loop = asyncio .new_event_loop ()
17
- yield loop
18
- loop .close ()
19
17
18
+ def teardown_module():
19
+ # parametrized 2 * 2 times: 2 for 'event_loop' and 2 for 'fix'
20
+ assert TESTS_COUNT == 4
20
21
21
- @pytest .fixture (params = ["a" , "b" ])
22
- async def fix (request ):
23
- await asyncio .sleep (0 )
24
- return request .param
25
22
23
+ @pytest.fixture(scope="module", params=[1, 2])
24
+ def event_loop(request):
25
+ request.param
26
+ loop = asyncio.new_event_loop()
27
+ yield loop
28
+ loop.close()
26
29
27
- @pytest .mark .asyncio
28
- async def test_parametrized_loop (fix ):
29
- await asyncio .sleep (0 )
30
- global TESTS_COUNT
31
- TESTS_COUNT += 1
30
+
31
+ @pytest_asyncio.fixture(params=["a", "b"])
32
+ async def fix(request):
33
+ await asyncio.sleep(0)
34
+ return request.param
35
+
36
+
37
+ @pytest.mark.asyncio
38
+ async def test_parametrized_loop(fix):
39
+ await asyncio.sleep(0)
40
+ global TESTS_COUNT
41
+ TESTS_COUNT += 1
42
+ """
43
+ )
44
+ )
45
+ result = pytester .runpytest_subprocess ("--asyncio-mode=strict" )
46
+ result .assert_outcomes (passed = 4 )
You can’t perform that action at this time.
0 commit comments