File tree 1 file changed +39
-26
lines changed
1 file changed +39
-26
lines changed Original file line number Diff line number Diff line change 1
- """Test if pytestmark works when defined in a module."""
2
- import asyncio
1
+ from textwrap import dedent
3
2
4
- import pytest
3
+ from pytest import Pytester
5
4
6
- pytestmark = pytest .mark .asyncio
7
5
6
+ def test_asyncio_mark_works_on_module_level (pytester : Pytester ):
7
+ pytester .makepyfile (
8
+ dedent (
9
+ """\
10
+ import asyncio
8
11
9
- class TestPyTestMark :
10
- async def test_is_asyncio (self , event_loop , sample_fixture ):
11
- assert asyncio .get_event_loop ()
12
+ import pytest
12
13
13
- counter = 1
14
+ pytestmark = pytest.mark.asyncio
14
15
15
- async def inc ():
16
- nonlocal counter
17
- counter += 1
18
- await asyncio .sleep (0 )
19
16
20
- await asyncio .ensure_future (inc ())
21
- assert counter == 2
17
+ class TestPyTestMark:
18
+ async def test_is_asyncio(self, event_loop, sample_fixture):
19
+ assert asyncio.get_event_loop()
22
20
21
+ counter = 1
23
22
24
- async def test_is_asyncio (event_loop , sample_fixture ):
25
- assert asyncio .get_event_loop ()
26
- counter = 1
23
+ async def inc():
24
+ nonlocal counter
25
+ counter += 1
26
+ await asyncio.sleep(0)
27
27
28
- async def inc ():
29
- nonlocal counter
30
- counter += 1
31
- await asyncio .sleep (0 )
28
+ await asyncio.ensure_future(inc())
29
+ assert counter == 2
32
30
33
- await asyncio .ensure_future (inc ())
34
- assert counter == 2
35
31
32
+ async def test_is_asyncio(event_loop, sample_fixture):
33
+ assert asyncio.get_event_loop()
34
+ counter = 1
36
35
37
- @pytest .fixture
38
- def sample_fixture ():
39
- return None
36
+ async def inc():
37
+ nonlocal counter
38
+ counter += 1
39
+ await asyncio.sleep(0)
40
+
41
+ await asyncio.ensure_future(inc())
42
+ assert counter == 2
43
+
44
+
45
+ @pytest.fixture
46
+ def sample_fixture():
47
+ return None
48
+ """
49
+ )
50
+ )
51
+ result = pytester .runpytest ("--asyncio-mode=strict" )
52
+ result .assert_outcomes (passed = 2 )
You can’t perform that action at this time.
0 commit comments