Skip to content

Commit 340f165

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent dcfd956 commit 340f165

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

src/_pytest/fixtures.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,11 @@ def getfixturevalue(self, argname: str) -> Any:
535535
"This can happen when the fixture has already been torn down."
536536
)
537537

538-
if (isinstance(fixturedef, FixtureDef)
539-
and fixturedef is not None
540-
and fixturedef.scope == Scope.Invocation.value):
538+
if (
539+
isinstance(fixturedef, FixtureDef)
540+
and fixturedef is not None
541+
and fixturedef.scope == Scope.Invocation.value
542+
):
541543
self._fixture_defs.pop(argname)
542544

543545
return fixturedef.cached_result[0]
@@ -626,7 +628,10 @@ def _get_active_fixturedef(
626628
finally:
627629
for arg_name in fixturedef.argnames:
628630
arg_fixture = self._fixture_defs.get(arg_name)
629-
if arg_fixture is not None and arg_fixture.scope == Scope.Invocation.value:
631+
if (
632+
arg_fixture is not None
633+
and arg_fixture.scope == Scope.Invocation.value
634+
):
630635
self._fixture_defs.pop(arg_name)
631636

632637
return fixturedef
@@ -769,7 +774,10 @@ def _check_scope(
769774
requested_fixturedef: FixtureDef[object] | PseudoFixtureDef[object],
770775
requested_scope: Scope,
771776
) -> None:
772-
if isinstance(requested_fixturedef, PseudoFixtureDef) or requested_scope == Scope.Invocation:
777+
if (
778+
isinstance(requested_fixturedef, PseudoFixtureDef)
779+
or requested_scope == Scope.Invocation
780+
):
773781
return
774782
if self._scope > requested_scope:
775783
# Try to report something helpful.

testing/test_no_cache.py

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from __future__ import annotations
2+
13
from _pytest.pytester import Pytester
24

35

4-
def test_setup_teardown_executed_for_every_fixture_usage_without_caching(pytester: Pytester) -> None:
6+
def test_setup_teardown_executed_for_every_fixture_usage_without_caching(
7+
pytester: Pytester,
8+
) -> None:
59
pytester.makepyfile(
610
"""
711
import pytest
@@ -26,17 +30,22 @@ def b(fixt):
2630
2731
def test(a, b, fixt):
2832
assert False
29-
""")
33+
"""
34+
)
3035

3136
result = pytester.runpytest("--log-level=INFO")
3237
assert result.ret == 1
33-
result.stdout.fnmatch_lines([
34-
*["*&&Setting up fixt&&*"] * 3,
35-
*["*&&Tearing down fixt&&*"] * 3,
36-
])
38+
result.stdout.fnmatch_lines(
39+
[
40+
*["*&&Setting up fixt&&*"] * 3,
41+
*["*&&Tearing down fixt&&*"] * 3,
42+
]
43+
)
3744

3845

39-
def test_setup_teardown_executed_for_every_getfixturevalue_usage_without_caching(pytester: Pytester) -> None:
46+
def test_setup_teardown_executed_for_every_getfixturevalue_usage_without_caching(
47+
pytester: Pytester,
48+
) -> None:
4049
pytester.makepyfile(
4150
"""
4251
import pytest
@@ -56,13 +65,17 @@ def test(request):
5665
)
5766
result = pytester.runpytest("--log-level=INFO")
5867
assert result.ret == 1
59-
result.stdout.fnmatch_lines([
60-
*["*&&Setting up fixt&&*"] * 3,
61-
*["*&&Tearing down fixt&&*"] * 3,
62-
])
68+
result.stdout.fnmatch_lines(
69+
[
70+
*["*&&Setting up fixt&&*"] * 3,
71+
*["*&&Tearing down fixt&&*"] * 3,
72+
]
73+
)
6374

6475

65-
def test_non_cached_fixture_generates_unique_values_per_usage(pytester: Pytester) -> None:
76+
def test_non_cached_fixture_generates_unique_values_per_usage(
77+
pytester: Pytester,
78+
) -> None:
6679
pytester.makepyfile(
6780
"""
6881
import pytest
@@ -71,25 +84,28 @@ def test_non_cached_fixture_generates_unique_values_per_usage(pytester: Pytester
7184
def random_num():
7285
import random
7386
return random.randint(-100_000_000_000, 100_000_000_000)
74-
75-
87+
88+
7689
@pytest.fixture()
7790
def a(random_num):
7891
return random_num
79-
80-
92+
93+
8194
@pytest.fixture()
8295
def b(random_num):
8396
return random_num
84-
85-
97+
98+
8699
def test(a, b, random_num):
87100
assert a != b != random_num
88-
""")
101+
"""
102+
)
89103
pytester.runpytest().assert_outcomes(passed=1)
90104

91105

92-
def test_non_cached_fixture_generates_unique_values_per_getfixturevalue_usage(pytester: Pytester) -> None:
106+
def test_non_cached_fixture_generates_unique_values_per_getfixturevalue_usage(
107+
pytester: Pytester,
108+
) -> None:
93109
pytester.makepyfile(
94110
"""
95111
import pytest
@@ -98,8 +114,8 @@ def test_non_cached_fixture_generates_unique_values_per_getfixturevalue_usage(py
98114
def random_num():
99115
import random
100116
yield random.randint(-100_000_000_000, 100_000_000_000)
101-
102-
117+
118+
103119
def test(request):
104120
random_nums = [request.getfixturevalue('random_num') for _ in range(3)]
105121
assert random_nums[0] != random_nums[1] != random_nums[2]

0 commit comments

Comments
 (0)