Wood Pecker
Wood Pecker

Reputation: 75

Understanding pytest-django test arguments

What are 'rf' and 'user_context' parameters and when are they assigned?

import pytest
from rest_framework import status
from rest_framework.reverse import reverse

from request_helper import pytest_request


@pytest.mark.urls(urls='api.urls')
@pytest.mark.django_db
def test_user_name_check_200(rf, users_context):
    data = {
        'username': 'test_jay_2'
    }
    url = reverse(viewname="users-check")
    response = pytest_request(rf,
                              method='get',
                              url=url,
                              user=None,
                              data=data)

    assert response.status_code == status.HTTP_200_OK

Upvotes: 1

Views: 389

Answers (1)

hoefling
hoefling

Reputation: 66171

Both are pytest fixtures (read about fixtures here: About fixtures). rf is defined in pytest-django (reference); a RequestFactory instance will be automatically injected for the rf argument in test. users_context is a fixture defined somewhere in your test project; search for something like

@pytest.fixture
def users_context():
    ...

in project code.

Upvotes: 1

Related Questions