Skip to content

Commit e495504

Browse files
authored
ruff: Addresses issues with ARG (#1239)
1 parent 85ed92b commit e495504

File tree

9 files changed

+97
-66
lines changed

9 files changed

+97
-66
lines changed

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ ignore = [
220220
"S101", # Use of `assert` detected
221221

222222
# TODO - need to fix these
223-
"ARG001", # Unused function argument
224-
"ARG002", # Unused method argument
225223
"C901", # .. is too complex
226224
"COM812", # Trailing comma missing
227225
"E501", # Line too long

pytest_django/fixtures.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ def django_db_modify_db_settings_xdist_suffix(request: pytest.FixtureRequest) ->
7575

7676
@pytest.fixture(scope="session")
7777
def django_db_modify_db_settings_parallel_suffix(
78-
django_db_modify_db_settings_tox_suffix: None,
79-
django_db_modify_db_settings_xdist_suffix: None,
78+
django_db_modify_db_settings_tox_suffix: None, # noqa: ARG001
79+
django_db_modify_db_settings_xdist_suffix: None, # noqa: ARG001
8080
) -> None:
8181
skip_if_no_django()
8282

8383

8484
@pytest.fixture(scope="session")
8585
def django_db_modify_db_settings(
86-
django_db_modify_db_settings_parallel_suffix: None,
86+
django_db_modify_db_settings_parallel_suffix: None, # noqa: ARG001
8787
) -> None:
8888
"""Modify db settings just before the databases are configured."""
8989
skip_if_no_django()
@@ -162,12 +162,12 @@ def _get_databases_for_setup(
162162
@pytest.fixture(scope="session")
163163
def django_db_setup(
164164
request: pytest.FixtureRequest,
165-
django_test_environment: None,
165+
django_test_environment: None, # noqa: ARG001
166166
django_db_blocker: DjangoDbBlocker,
167167
django_db_use_migrations: bool,
168168
django_db_keepdb: bool,
169169
django_db_createdb: bool,
170-
django_db_modify_db_settings: None,
170+
django_db_modify_db_settings: None, # noqa: ARG001
171171
) -> Generator[None, None, None]:
172172
"""Top level fixture to ensure test databases are available"""
173173
from django.test.utils import setup_databases, teardown_databases
@@ -206,7 +206,7 @@ def django_db_setup(
206206
@pytest.fixture
207207
def _django_db_helper(
208208
request: pytest.FixtureRequest,
209-
django_db_setup: None,
209+
django_db_setup: None, # noqa: ARG001
210210
django_db_blocker: DjangoDbBlocker,
211211
) -> Generator[None, None, None]:
212212
if is_django_unittest(request):
@@ -458,7 +458,7 @@ def async_client() -> django.test.AsyncClient:
458458

459459

460460
@pytest.fixture
461-
def django_user_model(db: None) -> _UserModel:
461+
def django_user_model(db: None) -> _UserModel: # noqa: ARG001
462462
"""The class of Django's user model."""
463463
from django.contrib.auth import get_user_model
464464

@@ -474,7 +474,7 @@ def django_username_field(django_user_model: _UserModel) -> str:
474474

475475
@pytest.fixture
476476
def admin_user(
477-
db: None,
477+
db: None, # noqa: ARG001
478478
django_user_model: _User,
479479
django_username_field: str,
480480
) -> _User:
@@ -505,7 +505,7 @@ def admin_user(
505505

506506
@pytest.fixture
507507
def admin_client(
508-
db: None,
508+
db: None, # noqa: ARG001
509509
admin_user: _User,
510510
) -> django.test.Client:
511511
"""A Django test client logged in as an admin user."""

pytest_django/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ def _dj_autoclear_mailbox() -> None:
609609

610610
@pytest.fixture
611611
def mailoutbox(
612-
django_mail_patch_dns: None,
612+
django_mail_patch_dns: None, # noqa: ARG001
613613
_dj_autoclear_mailbox: None,
614614
) -> list[django.core.mail.EmailMessage] | None:
615615
"""A clean email outbox to which Django-generated emails are sent."""
@@ -833,7 +833,7 @@ def _dj_db_wrapper(self) -> django.db.backends.base.base.BaseDatabaseWrapper:
833833
def _save_active_wrapper(self) -> None:
834834
self._history.append(self._dj_db_wrapper.ensure_connection)
835835

836-
def _blocking_wrapper(*args: Any, **kwargs: Any) -> NoReturn:
836+
def _blocking_wrapper(*args: Any, **kwargs: Any) -> NoReturn: # noqa: ARG002
837837
__tracebackhide__ = True
838838
raise RuntimeError(
839839
"Database access not allowed, "

pytest_django/runner.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(
1212
verbosity: int = 1,
1313
failfast: bool = False,
1414
keepdb: bool = False,
15-
**kwargs: Any,
15+
**kwargs: Any, # noqa: ARG002
1616
) -> None:
1717
self.verbosity = verbosity
1818
self.failfast = failfast
@@ -24,7 +24,11 @@ def add_arguments(cls, parser: ArgumentParser) -> None:
2424
"--keepdb", action="store_true", help="Preserves the test DB between runs."
2525
)
2626

27-
def run_tests(self, test_labels: Iterable[str], **kwargs: Any) -> int:
27+
def run_tests(
28+
self,
29+
test_labels: Iterable[str],
30+
**kwargs: Any, # noqa: ARG002
31+
) -> int:
2832
"""Run pytest and return the exitcode.
2933
3034
It translates some of Django's test command option to pytest's.

pytest_django_test/app/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ def admin_required_view(request: HttpRequest) -> HttpResponse:
1010
return HttpResponse(Template("You are an admin").render(Context()))
1111

1212

13-
def item_count(request: HttpRequest) -> HttpResponse:
13+
def item_count(request: HttpRequest) -> HttpResponse: # noqa: ARG001
1414
return HttpResponse(f"Item count: {Item.objects.count()}")

pytest_django_test/db_router.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
class DbRouter:
2-
def db_for_read(self, model, **hints):
2+
def db_for_read(self, model, **hints): # noqa: ARG002
33
if model._meta.app_label == "app" and model._meta.model_name == "seconditem":
44
return "second"
55
return None
66

7-
def db_for_write(self, model, **hints):
7+
def db_for_write(self, model, **hints): # noqa: ARG002
88
if model._meta.app_label == "app" and model._meta.model_name == "seconditem":
99
return "second"
1010
return None
1111

12-
def allow_migrate(self, db, app_label, model_name=None, **hints):
12+
def allow_migrate(self, db, app_label, model_name=None, **hints): # noqa: ARG002
1313
if app_label == "app" and model_name == "seconditem":
1414
return db == "second"

tests/test_database.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_noaccess_fixture(noaccess: None) -> None:
3939

4040

4141
@pytest.fixture
42-
def non_zero_sequences_counter(db: None) -> None:
42+
def non_zero_sequences_counter(db: None) -> None: # noqa: ARG001
4343
"""Ensure that the db's internal sequence counter is > 1.
4444
4545
This is used to test the `reset_sequences` feature.
@@ -73,28 +73,28 @@ def all_dbs(self, request: pytest.FixtureRequest) -> None:
7373
else:
7474
raise AssertionError() # pragma: no cover
7575

76-
def test_access(self, all_dbs: None) -> None:
76+
def test_access(self, all_dbs: None) -> None: # noqa: ARG002
7777
Item.objects.create(name="spam")
7878

79-
def test_clean_db(self, all_dbs: None) -> None:
79+
def test_clean_db(self, all_dbs: None) -> None: # noqa: ARG002
8080
# Relies on the order: test_access created an object
8181
assert Item.objects.count() == 0
8282

83-
def test_transactions_disabled(self, db: None) -> None:
83+
def test_transactions_disabled(self, db: None) -> None: # noqa: ARG002
8484
if not connection.features.supports_transactions:
8585
pytest.skip("transactions required for this test")
8686

8787
assert connection.in_atomic_block
8888

89-
def test_transactions_enabled(self, transactional_db: None) -> None:
89+
def test_transactions_enabled(self, transactional_db: None) -> None: # noqa: ARG002
9090
if not connection.features.supports_transactions:
9191
pytest.skip("transactions required for this test")
9292

9393
assert not connection.in_atomic_block
9494

9595
def test_transactions_enabled_via_reset_seq(
9696
self,
97-
django_db_reset_sequences: None,
97+
django_db_reset_sequences: None, # noqa: ARG002
9898
) -> None:
9999
if not connection.features.supports_transactions:
100100
pytest.skip("transactions required for this test")
@@ -103,9 +103,9 @@ def test_transactions_enabled_via_reset_seq(
103103

104104
def test_django_db_reset_sequences_fixture(
105105
self,
106-
db: None,
106+
db: None, # noqa: ARG002
107107
django_pytester: DjangoPytester,
108-
non_zero_sequences_counter: None,
108+
non_zero_sequences_counter: None, # noqa: ARG002
109109
) -> None:
110110
if not db_supports_reset_sequences():
111111
pytest.skip(
@@ -130,7 +130,11 @@ def test_django_db_reset_sequences_requested(
130130
result = django_pytester.runpytest_subprocess("-v", "--reuse-db")
131131
result.stdout.fnmatch_lines(["*test_django_db_reset_sequences_requested PASSED*"])
132132

133-
def test_serialized_rollback(self, db: None, django_pytester: DjangoPytester) -> None:
133+
def test_serialized_rollback(
134+
self,
135+
db: None, # noqa: ARG002
136+
django_pytester: DjangoPytester,
137+
) -> None:
134138
django_pytester.create_app_file(
135139
"""
136140
from django.db import migrations
@@ -176,25 +180,25 @@ def test_serialized_rollback_3():
176180
assert result.ret == 0
177181

178182
@pytest.fixture
179-
def mydb(self, all_dbs: None) -> None:
183+
def mydb(self, all_dbs: None) -> None: # noqa: ARG002
180184
# This fixture must be able to access the database
181185
Item.objects.create(name="spam")
182186

183-
def test_mydb(self, mydb: None) -> None:
187+
def test_mydb(self, mydb: None) -> None: # noqa: ARG002
184188
if not connection.features.supports_transactions:
185189
pytest.skip("transactions required for this test")
186190

187191
# Check the fixture had access to the db
188192
item = Item.objects.get(name="spam")
189193
assert item
190194

191-
def test_fixture_clean(self, all_dbs: None) -> None:
195+
def test_fixture_clean(self, all_dbs: None) -> None: # noqa: ARG002
192196
# Relies on the order: test_mydb created an object
193197
# See https://github.com/pytest-dev/pytest-django/issues/17
194198
assert Item.objects.count() == 0
195199

196200
@pytest.fixture
197-
def fin(self, request: pytest.FixtureRequest, all_dbs: None) -> Generator[None, None, None]:
201+
def fin(self, all_dbs: None) -> Generator[None, None, None]: # noqa: ARG002
198202
# This finalizer must be able to access the database
199203
yield
200204
Item.objects.create(name="spam")
@@ -203,27 +207,27 @@ def test_fin(self, fin: None) -> None:
203207
# Check finalizer has db access (teardown will fail if not)
204208
pass
205209

206-
def test_durable_transactions(self, all_dbs: None) -> None:
210+
def test_durable_transactions(self, all_dbs: None) -> None: # noqa: ARG002
207211
with transaction.atomic(durable=True):
208212
item = Item.objects.create(name="foo")
209213
assert Item.objects.get() == item
210214

211215

212216
class TestDatabaseFixturesAllOrder:
213217
@pytest.fixture
214-
def fixture_with_db(self, db: None) -> None:
218+
def fixture_with_db(self, db: None) -> None: # noqa: ARG002
215219
Item.objects.create(name="spam")
216220

217221
@pytest.fixture
218-
def fixture_with_transdb(self, transactional_db: None) -> None:
222+
def fixture_with_transdb(self, transactional_db: None) -> None: # noqa: ARG002
219223
Item.objects.create(name="spam")
220224

221225
@pytest.fixture
222-
def fixture_with_reset_sequences(self, django_db_reset_sequences: None) -> None:
226+
def fixture_with_reset_sequences(self, django_db_reset_sequences: None) -> None: # noqa: ARG002
223227
Item.objects.create(name="spam")
224228

225229
@pytest.fixture
226-
def fixture_with_serialized_rollback(self, django_db_serialized_rollback: None) -> None:
230+
def fixture_with_serialized_rollback(self, django_db_serialized_rollback: None) -> None: # noqa: ARG002
227231
Item.objects.create(name="ham")
228232

229233
def test_trans(self, fixture_with_transdb: None) -> None:
@@ -311,35 +315,35 @@ def test_databases(self, request: pytest.FixtureRequest) -> None:
311315
assert marker.kwargs["databases"] == ["default", "replica", "second"]
312316

313317
@pytest.mark.django_db(databases=["second"])
314-
def test_second_database(self, request: pytest.FixtureRequest) -> None:
318+
def test_second_database(self) -> None:
315319
SecondItem.objects.create(name="spam")
316320

317321
@pytest.mark.django_db(databases=["default"])
318-
def test_not_allowed_database(self, request: pytest.FixtureRequest) -> None:
322+
def test_not_allowed_database(self) -> None:
319323
with pytest.raises(AssertionError, match="not allowed"):
320324
SecondItem.objects.count()
321325
with pytest.raises(AssertionError, match="not allowed"):
322326
SecondItem.objects.create(name="spam")
323327

324328
@pytest.mark.django_db(databases=["replica"])
325-
def test_replica_database(self, request: pytest.FixtureRequest) -> None:
329+
def test_replica_database(self) -> None:
326330
Item.objects.using("replica").count()
327331

328332
@pytest.mark.django_db(databases=["replica"])
329-
def test_replica_database_not_allowed(self, request: pytest.FixtureRequest) -> None:
333+
def test_replica_database_not_allowed(self) -> None:
330334
with pytest.raises(AssertionError, match="not allowed"):
331335
Item.objects.count()
332336

333337
@pytest.mark.django_db(transaction=True, databases=["default", "replica"])
334-
def test_replica_mirrors_default_database(self, request: pytest.FixtureRequest) -> None:
338+
def test_replica_mirrors_default_database(self) -> None:
335339
Item.objects.create(name="spam")
336340
Item.objects.using("replica").create(name="spam")
337341

338342
assert Item.objects.count() == 2
339343
assert Item.objects.using("replica").count() == 2
340344

341345
@pytest.mark.django_db(databases="__all__")
342-
def test_all_databases(self, request: pytest.FixtureRequest) -> None:
346+
def test_all_databases(self) -> None:
343347
Item.objects.count()
344348
Item.objects.create(name="spam")
345349
SecondItem.objects.count()
@@ -369,15 +373,15 @@ def test_available_apps_enabled(self, request: pytest.FixtureRequest) -> None:
369373
assert marker.kwargs["available_apps"] == ["pytest_django_test.app"]
370374

371375
@pytest.mark.django_db
372-
def test_available_apps_default(self, request: pytest.FixtureRequest) -> None:
376+
def test_available_apps_default(self) -> None:
373377
from django.apps import apps
374378
from django.conf import settings
375379

376380
for app in settings.INSTALLED_APPS:
377381
assert apps.is_installed(app)
378382

379383
@pytest.mark.django_db(available_apps=["pytest_django_test.app"])
380-
def test_available_apps_limited(self, request: pytest.FixtureRequest) -> None:
384+
def test_available_apps_limited(self) -> None:
381385
from django.apps import apps
382386
from django.conf import settings
383387

0 commit comments

Comments
 (0)