Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Compatibility

* Official Django 6.1 support.

Improvements
^^^^^^^^^^^^

* Added :fixture:`request_factory` as a readable alias for :fixture:`rf`
(`#1252 <https://github.com/pytest-dev/pytest-django/issues/1252>`__).

v4.14.0 (2026-08-10)
--------------------

Expand Down
18 changes: 18 additions & 0 deletions docs/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ More information on fixtures is available in the :ref:`pytest documentation

An instance of a :class:`django.test.RequestFactory`.

Also available as :fixture:`request_factory`.

Example
"""""""

Expand All @@ -204,6 +206,22 @@ Example
response = my_view(request)
assert response.status_code == 200

.. fixture:: request_factory

``request_factory`` - ``RequestFactory``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A readable alias for :fixture:`rf`. Both fixtures return the same
:class:`django.test.RequestFactory` instance within a test, including when
``rf`` is overridden by a custom fixture.

Example::

def test_request(request_factory):
request = request_factory.get('/example/', {'name': 'pytest-django'})
assert request.path == '/example/'
assert request.GET['name'] == 'pytest-django'

.. fixture:: async_rf

``async_rf`` - ``AsyncRequestFactory``
Expand Down
7 changes: 7 additions & 0 deletions pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"django_user_model",
"django_username_field",
"live_server",
"request_factory",
"rf",
"settings",
"transactional_db",
Expand Down Expand Up @@ -538,6 +539,12 @@ def rf() -> django.test.RequestFactory:
return RequestFactory()


@pytest.fixture
def request_factory(rf: django.test.RequestFactory) -> django.test.RequestFactory:
"""Alias for the rf fixture."""
return rf


@pytest.fixture
def async_rf() -> django.test.AsyncRequestFactory:
"""AsyncRequestFactory instance"""
Expand Down
1 change: 1 addition & 0 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
django_user_model, # noqa: F401
django_username_field, # noqa: F401
live_server, # noqa: F401
request_factory, # noqa: F401
rf, # noqa: F401
settings, # noqa: F401
transactional_db, # noqa: F401
Expand Down
12 changes: 12 additions & 0 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ def test_rf(rf: RequestFactory) -> None:
assert isinstance(rf, RequestFactory)


def test_request_factory(request_factory: RequestFactory) -> None:
assert isinstance(request_factory, RequestFactory)
request = request_factory.get("/example/", {"name": "pytest-django"})
assert request.method == "GET"
assert request.path == "/example/"
assert request.GET["name"] == "pytest-django"


def test_request_factory_alias(rf: RequestFactory, request_factory: RequestFactory) -> None:
assert request_factory is rf


def test_async_rf(async_rf: AsyncRequestFactory) -> None:
assert isinstance(async_rf, AsyncRequestFactory)

Expand Down