Skip to content

Commit

Permalink
bit more explicit use case for configure + settings fixture (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
minusf committed Oct 24, 2020
1 parent e4ebc59 commit bc9cda3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/configuring_django.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ INI File Contents::
Using ``django.conf.settings.configure()``
------------------------------------------

Django settings can be set up by calling ``django.conf.settings.configure()``.
In case there is no ``DJANGO_SETTINGS_MODULE``, the ``settings`` object can be
created by calling ``django.conf.settings.configure()``.

This can be done from your project's ``conftest.py`` file::

Expand All @@ -85,6 +86,22 @@ This can be done from your project's ``conftest.py`` file::
def pytest_configure():
settings.configure(DATABASES=...)

Overriding individual settings
------------------------------

Settings can be overridden by using the :fixture:`settings` fixture::

@pytest.fixture(autouse=True)
def use_dummy_cache_backend(settings):
settings.CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
}

Here `autouse=True` is used, meaning the fixture is automatically applied to all tests,
but it can also be requested individually per-test.

Changing your app before Django gets set up
-------------------------------------------

Expand Down

0 comments on commit bc9cda3

Please sign in to comment.