Amir Afianian
Amir Afianian

Reputation: 2797

How to mock django settings attributes in pytest-django

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?

Upvotes: 3

Views: 2515

Answers (1)

Tom Carrick
Tom Carrick

Reputation: 6616

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

Upvotes: 6

Related Questions