How to mock django settings attributes in pytest-django

Viewed 736

When using Django default unittest it's trivial to patch settings attributes (using @override_settings decorator for instance.)

I'd like to override several attributes of my settings for a test method. How can I go about achieving this when I'm using pytest-django?

1 Answers

You can pass in settings as a test fixture, then modify it how you need. Here's an example from the documentation:

def test_with_specific_settings(settings):
    settings.USE_TZ = True
    assert settings.USE_TZ
Related