Skip to content

Commit f8ddf32

Browse files
committed
refactor: Address formatting issues recently found by shed.
1 parent 0d7a92e commit f8ddf32

26 files changed

+343
-930
lines changed

pytest_asyncio/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _apply_contextvar_changes(
403403

404404
def restore_contextvars():
405405
while context_tokens:
406-
(var, token) = context_tokens.pop()
406+
var, token = context_tokens.pop()
407407
var.reset(token)
408408

409409
return restore_contextvars

tests/async_fixtures/test_async_fixtures_contextvars.py

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import pytest
1212
from pytest import Pytester
1313

14-
_prelude = dedent(
15-
"""
14+
_prelude = dedent("""
1615
import pytest
1716
import pytest_asyncio
1817
from contextlib import contextmanager
@@ -27,16 +26,12 @@ def context_var_manager(value):
2726
yield
2827
finally:
2928
_context_var.reset(token)
30-
"""
31-
)
29+
""")
3230

3331

3432
def test_var_from_sync_generator_propagates_to_async(pytester: Pytester):
3533
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
36-
pytester.makepyfile(
37-
_prelude
38-
+ dedent(
39-
"""
34+
pytester.makepyfile(_prelude + dedent("""
4035
@pytest.fixture
4136
def var_fixture():
4237
with context_var_manager("value"):
@@ -49,19 +44,14 @@ async def check_var_fixture(var_fixture):
4944
@pytest.mark.asyncio
5045
async def test(check_var_fixture):
5146
assert _context_var.get() == "value"
52-
"""
53-
)
54-
)
47+
"""))
5548
result = pytester.runpytest("--asyncio-mode=strict")
5649
result.assert_outcomes(passed=1)
5750

5851

5952
def test_var_from_async_generator_propagates_to_sync(pytester: Pytester):
6053
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
61-
pytester.makepyfile(
62-
_prelude
63-
+ dedent(
64-
"""
54+
pytester.makepyfile(_prelude + dedent("""
6555
@pytest_asyncio.fixture
6656
async def var_fixture():
6757
with context_var_manager("value"):
@@ -74,19 +64,14 @@ def check_var_fixture(var_fixture):
7464
@pytest.mark.asyncio
7565
async def test(check_var_fixture):
7666
assert _context_var.get() == "value"
77-
"""
78-
)
79-
)
67+
"""))
8068
result = pytester.runpytest("--asyncio-mode=strict")
8169
result.assert_outcomes(passed=1)
8270

8371

8472
def test_var_from_async_fixture_propagates_to_sync(pytester: Pytester):
8573
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
86-
pytester.makepyfile(
87-
_prelude
88-
+ dedent(
89-
"""
74+
pytester.makepyfile(_prelude + dedent("""
9075
@pytest_asyncio.fixture
9176
async def var_fixture():
9277
_context_var.set("value")
@@ -98,19 +83,14 @@ def check_var_fixture(var_fixture):
9883
9984
def test(check_var_fixture):
10085
assert _context_var.get() == "value"
101-
"""
102-
)
103-
)
86+
"""))
10487
result = pytester.runpytest("--asyncio-mode=strict")
10588
result.assert_outcomes(passed=1)
10689

10790

10891
def test_var_from_generator_reset_before_previous_fixture_cleanup(pytester: Pytester):
10992
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
110-
pytester.makepyfile(
111-
_prelude
112-
+ dedent(
113-
"""
93+
pytester.makepyfile(_prelude + dedent("""
11494
@pytest_asyncio.fixture
11595
async def no_var_fixture():
11696
with pytest.raises(LookupError):
@@ -127,19 +107,14 @@ async def var_fixture(no_var_fixture):
127107
@pytest.mark.asyncio
128108
async def test(var_fixture):
129109
assert _context_var.get() == "value"
130-
"""
131-
)
132-
)
110+
"""))
133111
result = pytester.runpytest("--asyncio-mode=strict")
134112
result.assert_outcomes(passed=1)
135113

136114

137115
def test_var_from_fixture_reset_before_previous_fixture_cleanup(pytester: Pytester):
138116
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
139-
pytester.makepyfile(
140-
_prelude
141-
+ dedent(
142-
"""
117+
pytester.makepyfile(_prelude + dedent("""
143118
@pytest_asyncio.fixture
144119
async def no_var_fixture():
145120
with pytest.raises(LookupError):
@@ -156,19 +131,14 @@ async def var_fixture(no_var_fixture):
156131
@pytest.mark.asyncio
157132
async def test(var_fixture):
158133
assert _context_var.get() == "value"
159-
"""
160-
)
161-
)
134+
"""))
162135
result = pytester.runpytest("--asyncio-mode=strict")
163136
result.assert_outcomes(passed=1)
164137

165138

166139
def test_var_previous_value_restored_after_fixture(pytester: Pytester):
167140
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
168-
pytester.makepyfile(
169-
_prelude
170-
+ dedent(
171-
"""
141+
pytester.makepyfile(_prelude + dedent("""
172142
@pytest_asyncio.fixture
173143
async def var_fixture_1():
174144
with context_var_manager("value1"):
@@ -184,19 +154,14 @@ async def var_fixture_2(var_fixture_1):
184154
@pytest.mark.asyncio
185155
async def test(var_fixture_2):
186156
assert _context_var.get() == "value2"
187-
"""
188-
)
189-
)
157+
"""))
190158
result = pytester.runpytest("--asyncio-mode=strict")
191159
result.assert_outcomes(passed=1)
192160

193161

194162
def test_var_set_to_existing_value_ok(pytester: Pytester):
195163
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
196-
pytester.makepyfile(
197-
_prelude
198-
+ dedent(
199-
"""
164+
pytester.makepyfile(_prelude + dedent("""
200165
@pytest_asyncio.fixture
201166
async def var_fixture():
202167
with context_var_manager("value"):
@@ -210,18 +175,14 @@ async def same_var_fixture(var_fixture):
210175
@pytest.mark.asyncio
211176
async def test(same_var_fixture):
212177
assert _context_var.get() == "value"
213-
"""
214-
)
215-
)
178+
"""))
216179
result = pytester.runpytest("--asyncio-mode=strict")
217180
result.assert_outcomes(passed=1)
218181

219182

220183
def test_no_isolation_against_context_changes_in_sync_tests(pytester: Pytester):
221184
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
222-
pytester.makepyfile(
223-
dedent(
224-
"""
185+
pytester.makepyfile(dedent("""
225186
import pytest
226187
import pytest_asyncio
227188
from contextvars import ContextVar
@@ -234,9 +195,7 @@ def test_sync():
234195
@pytest.mark.asyncio
235196
async def test_async():
236197
assert _context_var.get() == "new_value"
237-
"""
238-
)
239-
)
198+
"""))
240199
result = pytester.runpytest("--asyncio-mode=strict")
241200
result.assert_outcomes(passed=2)
242201

@@ -246,9 +205,7 @@ def test_isolation_against_context_changes_in_async_tests(
246205
pytester: Pytester, loop_scope: Literal["function", "module"]
247206
):
248207
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
249-
pytester.makepyfile(
250-
dedent(
251-
f"""
208+
pytester.makepyfile(dedent(f"""
252209
import pytest
253210
import pytest_asyncio
254211
from contextvars import ContextVar
@@ -263,8 +220,6 @@ async def test_async_first():
263220
async def test_async_second():
264221
with pytest.raises(LookupError):
265222
_context_var.get()
266-
"""
267-
)
268-
)
223+
"""))
269224
result = pytester.runpytest("--asyncio-mode=strict")
270225
result.assert_outcomes(passed=2)

tests/async_fixtures/test_shared_module_fixture.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,24 @@ def test_asyncio_mark_provides_package_scoped_loop_strict_mode(pytester: Pyteste
99
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
1010
pytester.makepyfile(
1111
__init__="",
12-
conftest=dedent(
13-
"""\
12+
conftest=dedent("""\
1413
import pytest_asyncio
1514
@pytest_asyncio.fixture(loop_scope="module", scope="module")
1615
async def async_shared_module_fixture():
1716
return True
18-
"""
19-
),
20-
test_module_one=dedent(
21-
"""\
17+
"""),
18+
test_module_one=dedent("""\
2219
import pytest
2320
@pytest.mark.asyncio
2421
async def test_shared_module_fixture_use_a(async_shared_module_fixture):
2522
assert async_shared_module_fixture is True
26-
"""
27-
),
28-
test_module_two=dedent(
29-
"""\
23+
"""),
24+
test_module_two=dedent("""\
3025
import pytest
3126
@pytest.mark.asyncio
3227
async def test_shared_module_fixture_use_b(async_shared_module_fixture):
3328
assert async_shared_module_fixture is True
34-
"""
35-
),
29+
"""),
3630
)
3731
result = pytester.runpytest("--asyncio-mode=strict")
3832
result.assert_outcomes(passed=2)

tests/hypothesis/test_base.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@
1414

1515
def test_hypothesis_given_decorator_before_asyncio_mark(pytester: Pytester):
1616
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
17-
pytester.makepyfile(
18-
dedent(
19-
"""\
17+
pytester.makepyfile(dedent("""\
2018
import pytest
2119
from hypothesis import given, strategies as st
2220
2321
@given(st.integers())
2422
@pytest.mark.asyncio
2523
async def test_mark_inner(n):
2624
assert isinstance(n, int)
27-
"""
28-
)
29-
)
25+
"""))
3026
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
3127
result.assert_outcomes(passed=1)
3228

@@ -47,9 +43,7 @@ async def test_mark_and_parametrize(x, y):
4743

4844
def test_async_auto_marked(pytester: Pytester):
4945
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
50-
pytester.makepyfile(
51-
dedent(
52-
"""\
46+
pytester.makepyfile(dedent("""\
5347
import asyncio
5448
import pytest
5549
from hypothesis import given
@@ -60,19 +54,15 @@ def test_async_auto_marked(pytester: Pytester):
6054
@given(n=st.integers())
6155
async def test_hypothesis(n: int):
6256
assert isinstance(n, int)
63-
"""
64-
)
65-
)
57+
"""))
6658
result = pytester.runpytest("--asyncio-mode=auto")
6759
result.assert_outcomes(passed=1)
6860

6961

7062
def test_sync_not_auto_marked(pytester: Pytester):
7163
"""Assert that synchronous Hypothesis functions are not marked with asyncio"""
7264
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
73-
pytester.makepyfile(
74-
dedent(
75-
"""\
65+
pytester.makepyfile(dedent("""\
7666
import asyncio
7767
import pytest
7868
from hypothesis import given
@@ -85,8 +75,6 @@ def test_hypothesis(request, n: int):
8575
markers = [marker.name for marker in request.node.own_markers]
8676
assert "asyncio" not in markers
8777
assert isinstance(n, int)
88-
"""
89-
)
90-
)
78+
"""))
9179
result = pytester.runpytest("--asyncio-mode=auto")
9280
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)