[Django]-Is there any way to get the default domain of Client() in unittest of Django?

9👍

The default domain name for Django’s test client is testserver. It’s hardcoded in the RequestFactory base class.

If you want to change the domain for the specific request, you can just pass it as the kwarg:

self.client.get('/some-path', SERVER_NAME="anotherdomain.com")

0👍

I just tried https://docs.djangoproject.com/en/1.9/topics/testing/tools/#liveservertestcase

The default test URL will be http://localhost:8082 and we can request to the same while running tests. And its working for me.

0👍

is this the (pytest) answer you are looking for?

@pytest.fixture()
def client() -> "django.test.client.Client":
    """like the default pytest client with a new domain name."""
    skip_if_no_django()
    return Client(SERVER_NAME = 'my-server.com')
👤George

Leave a comment