Skip to content

Commit c257569

Browse files
authored
Makes the djt change adam suggested
1 parent d08d16c commit c257569

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

docs/helpers.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Assertions
77
----------
88

99
All of Django's :class:`~django:django.test.TestCase`
10-
:ref:`django:assertions` are available in via the :fixture:`django_testcase` fixture.
10+
:ref:`django:assertions` are available in via the :fixture:`djt` fixture.
1111

1212
Markers
1313
-------
@@ -274,9 +274,9 @@ Example
274274
Using the `admin_client` fixture will cause the test to automatically be marked
275275
for database use (no need to specify the :func:`~pytest.mark.django_db` mark).
276276

277-
.. fixture:: django_testcase
277+
.. fixture:: djt
278278

279-
``django_testcase`` - Django test case assertions
279+
``djt`` - Django test case assertions
280280
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281281

282282
Instance of the test case class. This fixture is particularly useful when you want
@@ -287,12 +287,12 @@ Example
287287

288288
::
289289

290-
def test_add(django_testcase):
291-
django_testcase.assertEqual(1 + 1, 2)
292-
django_testcase.assertXMLEqual(..., ...)
293-
django_testcase.assertJSONEqual(..., ...)
290+
def test_add(djt):
291+
djt.assertEqual(1 + 1, 2)
292+
djt.assertXMLEqual(..., ...)
293+
djt.assertJSONEqual(..., ...)
294294

295-
with django_testcase.assertNumQueries(2):
295+
with djt.assertNumQueries(2):
296296
some_function()
297297

298298
.. fixture:: admin_user

pytest_django/asserts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _wrapper(name: str):
3434
def assertion_func(*args, **kwargs):
3535
message = (
3636
f"Using pytest_django.asserts.{name} is deprecated. "
37-
f'Use fixture "django_testcase" and django_testcase.{name} instead.'
37+
f'Use fixture "djt" and djt.{name} instead.'
3838
)
3939
warnings.warn(
4040
message,

pytest_django/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def _set_suffix_to_test_databases(suffix: str) -> None:
378378
# ############### User visible fixtures ################
379379

380380

381-
@pytest.fixture
381+
@pytest.fixture(name="djt")
382382
def django_testcase(_django_db_helper: django.test.TestCase | None) -> django.test.TestCase | None:
383383
return _django_db_helper
384384

tests/test_asserts.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ def test_sanity() -> None:
7676
assert assertContains.__doc__
7777

7878

79-
def test_fixture_assert(django_testcase: django.test.TestCase) -> None:
80-
django_testcase.assertEqual("a", "a") # noqa: PT009
79+
def test_fixture_assert(djt: django.test.TestCase) -> None:
80+
djt.assertEqual("a", "a") # noqa: PT009
8181

8282
with pytest.raises(AssertionError):
83-
django_testcase.assertXMLEqual("a" * 10_000, "a")
83+
djt.assertXMLEqual("a" * 10_000, "a")
8484

8585

8686
class TestInternalDjangoAssert:
87-
def test_fixture_assert(self, django_testcase: django.test.TestCase) -> None:
88-
assert django_testcase != self
89-
django_testcase.assertEqual("a", "a") # noqa: PT009
87+
def test_fixture_assert(self, djt: django.test.TestCase) -> None:
88+
assert djt != self
89+
djt.assertEqual("a", "a") # noqa: PT009
9090
assert not hasattr(self, "assertEqual")
9191

9292
with pytest.raises(AssertionError):
93-
django_testcase.assertXMLEqual("a" * 10_000, "a")
93+
djt.assertXMLEqual("a" * 10_000, "a")
9494

9595

9696
@pytest.mark.django_project(create_manage_py=True)
@@ -101,7 +101,7 @@ def test_django_test_case_assert(django_pytester: DjangoPytester) -> None:
101101
import django.test
102102
103103
class TestDjangoAssert(django.test.TestCase):
104-
def test_fixture_assert(self, django_testcase: django.test.TestCase) -> None:
104+
def test_fixture_assert(self, djt: django.test.TestCase) -> None:
105105
assert False, "Cannot use the fixture"
106106
107107
def test_normal_assert(self) -> None:
@@ -112,7 +112,7 @@ def test_normal_assert(self) -> None:
112112
)
113113
result = django_pytester.runpytest_subprocess()
114114
result.assert_outcomes(failed=1, passed=1)
115-
assert "missing 1 required positional argument: 'django_testcase'" in result.stdout.str()
115+
assert "missing 1 required positional argument: 'djt'" in result.stdout.str()
116116

117117

118118
@pytest.mark.django_project(create_manage_py=True)
@@ -122,7 +122,7 @@ def test_unittest_assert(django_pytester: DjangoPytester) -> None:
122122
import unittest
123123
124124
class TestUnittestAssert(unittest.TestCase):
125-
def test_fixture_assert(self, django_testcase: unittest.TestCase) -> None:
125+
def test_fixture_assert(self, djt: unittest.TestCase) -> None:
126126
assert False, "Cannot use the fixture"
127127
128128
def test_normal_assert(self) -> None:
@@ -131,4 +131,4 @@ def test_normal_assert(self) -> None:
131131
)
132132
result = django_pytester.runpytest_subprocess()
133133
result.assert_outcomes(failed=1, passed=1)
134-
assert "missing 1 required positional argument: 'django_testcase'" in result.stdout.str()
134+
assert "missing 1 required positional argument: 'djt'" in result.stdout.str()

0 commit comments

Comments
 (0)