Skip to content

Commit 1950bfc

Browse files
committed
Update dependencies and improve code quality
- Bump versions of linting tools in pyproject.toml for better compatibility and features. - Add missing copyright notice to ignore list. - Refactor variable names in fixtures for clarity. - Add noqa comments to suppress linting warnings in specific functions. - Update test assertions for better readability and consistency. These changes enhance the maintainability and functionality of the codebase.
1 parent 9d6570a commit 1950bfc

8 files changed

Lines changed: 46 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ xdist = [
6565
linting = [
6666
"editorconfig-checker==3.2.1",
6767
"mypy==1.17.1",
68-
"ruff==0.12.8",
68+
"ruff==0.16.1",
6969
"zizmor==1.11.0",
7070
]
7171
[project.urls]
@@ -219,6 +219,7 @@ ignore = [
219219
"S101", # Use of `assert` detected
220220

221221
# TODO - need to fix these
222+
"CPY001", # Missing copyright notice at top of file
222223
"C901", # .. is too complex
223224
"COM812", # Trailing comma missing
224225
"E501", # Line too long

pytest_django/asserts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Dynamically load all Django assertion cases and expose them for importing.
33
"""
4+
# ruff: noqa: PLR0917
45

56
from __future__ import annotations
67

pytest_django/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def _get_databases_for_test(test: pytest.Item) -> tuple[Iterable[str], bool]:
124124
marker_db = test.get_closest_marker("django_db")
125125
if marker_db:
126126
(
127-
transaction,
128-
reset_sequences,
127+
_transaction,
128+
_reset_sequences,
129129
databases,
130130
serialized_rollback,
131-
available_apps,
131+
_available_apps,
132132
) = validate_django_db(marker_db)
133133
elif "db" in fixtures or "transactional_db" in fixtures or "live_server" in fixtures:
134134
serialized_rollback = "django_db_serialized_rollback" in fixtures
@@ -160,7 +160,7 @@ def _get_databases_for_setup(
160160

161161

162162
@pytest.fixture(scope="session")
163-
def django_db_setup(
163+
def django_db_setup( # noqa: PLR0917
164164
request: pytest.FixtureRequest,
165165
django_test_environment: None, # noqa: ARG001
166166
django_db_blocker: DjangoDbBlocker,

pytest_django/plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _setup_django(config: pytest.Config) -> None:
251251

252252

253253
def _get_boolean_value(
254-
x: None | (bool | str),
254+
x: bool | str | None,
255255
name: str,
256256
default: bool | None = None,
257257
) -> bool:
@@ -470,9 +470,9 @@ def get_order_number(test: pytest.Item) -> int:
470470
(
471471
transaction,
472472
reset_sequences,
473-
databases,
474-
serialized_rollback,
475-
available_apps,
473+
_databases,
474+
_serialized_rollback,
475+
_available_apps,
476476
) = validate_django_db(marker_db)
477477
uses_db = True
478478
transactional = transaction or reset_sequences

tests/test_database.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ def test_db_access_3(self):
435435
"*test_db_access_2 FAILED*",
436436
"*test_db_access_3 FAILED*",
437437
"*ERROR at setup of TestCase_setupClass.test_db_access_1*",
438-
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
439-
'or the "db" or "transactional_db" fixtures to enable it.',
438+
(
439+
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
440+
'or the "db" or "transactional_db" fixtures to enable it.'
441+
),
440442
]
441443
)
442444

@@ -477,8 +479,10 @@ def test_db_access_in_conftest(self, django_pytester: DjangoPytester) -> None:
477479
result = django_pytester.runpytest_subprocess("-v")
478480
result.stderr.fnmatch_lines(
479481
[
480-
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
481-
'or the "db" or "transactional_db" fixtures to enable it.*'
482+
(
483+
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
484+
'or the "db" or "transactional_db" fixtures to enable it.*'
485+
)
482486
]
483487
)
484488

@@ -493,7 +497,9 @@ def test_db_access_in_test_module(self, django_pytester: DjangoPytester) -> None
493497
result = django_pytester.runpytest_subprocess("-v")
494498
result.stdout.fnmatch_lines(
495499
[
496-
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
497-
'or the "db" or "transactional_db" fixtures to enable it.'
500+
(
501+
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
502+
'or the "db" or "transactional_db" fixtures to enable it.'
503+
)
498504
]
499505
)

tests/test_django_configurations.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def test_settings():
4444
result = pytester.runpytest_subprocess()
4545
result.stdout.fnmatch_lines(
4646
[
47-
"django: version: *, settings: tpkg.settings_env (from env), "
48-
"configuration: MySettings (from env)",
47+
(
48+
"django: version: *, settings: tpkg.settings_env (from env), "
49+
"configuration: MySettings (from env)"
50+
),
4951
"* 1 passed*",
5052
]
5153
)
@@ -78,8 +80,10 @@ def test_ds():
7880
result = pytester.runpytest_subprocess()
7981
result.stdout.fnmatch_lines(
8082
[
81-
"django: version: *, settings: tpkg.settings_env (from env), "
82-
"configuration: MySettings (from env)",
83+
(
84+
"django: version: *, settings: tpkg.settings_env (from env), "
85+
"configuration: MySettings (from env)"
86+
),
8387
"* 1 passed*",
8488
]
8589
)
@@ -111,8 +115,10 @@ def test_ds():
111115
result = pytester.runpytest_subprocess()
112116
result.stdout.fnmatch_lines(
113117
[
114-
"django: version: *, settings: tpkg.settings_ini (from ini), "
115-
"configuration: MySettings (from ini)",
118+
(
119+
"django: version: *, settings: tpkg.settings_ini (from ini), "
120+
"configuration: MySettings (from ini)"
121+
),
116122
"* 1 passed*",
117123
]
118124
)
@@ -145,8 +151,10 @@ def test_ds():
145151
result = pytester.runpytest_subprocess("--ds=tpkg.settings_opt", "--dc=MySettings")
146152
result.stdout.fnmatch_lines(
147153
[
148-
"django: version: *, settings: tpkg.settings_opt (from option),"
149-
" configuration: MySettings (from option)",
154+
(
155+
"django: version: *, settings: tpkg.settings_opt (from option),"
156+
" configuration: MySettings (from option)"
157+
),
150158
"* 1 passed*",
151159
]
152160
)

tests/test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def test_database_rollback_again() -> None:
294294

295295
@pytest.mark.django_db
296296
def test_database_name() -> None:
297-
dirname, name = os.path.split(connection.settings_dict["NAME"])
297+
_dirname, name = os.path.split(connection.settings_dict["NAME"])
298298
assert "file:memorydb" in name or name == ":memory:" or name.startswith("test_")
299299

300300

tests/test_fixtures.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ def test_django_assert_max_num_queries_db(
139139
Item.objects.create(name="3-quux")
140140

141141
assert excinfo.value.args == (
142-
"Expected to perform 2 queries or less but 3 were done "
143-
"(add -v option to show queries)",
142+
(
143+
"Expected to perform 2 queries or less but 3 were done "
144+
"(add -v option to show queries)"
145+
),
144146
)
145147
assert len(captured.captured_queries) == 3
146148
assert "1-foo" in captured.captured_queries[0]["sql"]
@@ -766,15 +768,15 @@ class Test_django_db_blocker:
766768
def test_block_manually(self, django_db_blocker: DjangoDbBlocker) -> None:
767769
try:
768770
django_db_blocker.block()
769-
with pytest.raises(RuntimeError, match="^Database access not allowed,"):
771+
with pytest.raises(RuntimeError, match=r"^Database access not allowed,"):
770772
Item.objects.exists()
771773
finally:
772774
django_db_blocker.restore()
773775

774776
@pytest.mark.django_db
775777
def test_block_with_block(self, django_db_blocker: DjangoDbBlocker) -> None:
776778
with django_db_blocker.block():
777-
with pytest.raises(RuntimeError, match="^Database access not allowed,"):
779+
with pytest.raises(RuntimeError, match=r"^Database access not allowed,"):
778780
Item.objects.exists()
779781

780782
def test_unblock_manually(self, django_db_blocker: DjangoDbBlocker) -> None:

0 commit comments

Comments
 (0)