Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#15561 closed New feature (fixed)

Factorize settings manipulation in tests

Reported by: Claude Paroz Owned by: Łukasz Rekucki
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX:

Description

I found a rather good implementation of django settings altering in the mail regression tests, and found that it could be reused in a lot of other Django tests, and of course in all Django applications.

So I'm proposing to take the alter_django_settings/restore_django_settings functions and the with_django_settings decorator out from regressiontests/mail/tests.py and offer these in general Django test utilities.

Attachments (5)

15561-1.diff (3.2 KB) - added by Claude Paroz 6 years ago.
Add settings manipulation functions in django test utilities
15561-i18n-tests.diff (11.3 KB) - added by Claude Paroz 6 years ago.
As an example, apply new test utils to i18n tests
15561.2.diff (12.2 KB) - added by Jannis Leidel 6 years ago.
with_settings decorator/context manager combo
15561.3.diff (12.3 KB) - added by Jannis Leidel 6 years ago.
Renamed to override_settings
15561.4.diff (14.9 KB) - added by Jannis Leidel 6 years ago.
Extended docs.

Download all attachments as: .zip

Change History (17)

Changed 6 years ago by Claude Paroz

Attachment: 15561-1.diff added

Add settings manipulation functions in django test utilities

Changed 6 years ago by Claude Paroz

Attachment: 15561-i18n-tests.diff added

As an example, apply new test utils to i18n tests

comment:1 Changed 6 years ago by Russell Keith-Magee

milestone: 1.4
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Agreed, this is a good idea, both for Django's own test suite, and as a tool that could be used by the broader community.

One thing that might be worth considering -- there are certain settings that, if changed, cause values to be cached. For example, when you set L10N and access date/number formatting operations, the formats are cached. It would be good to include the cache flushing operations as an automatic part of this settings decorator.

It would also be good if the decorator worked as a class decorator, as well as a method decorator.

comment:2 Changed 6 years ago by Łukasz Rekucki

Related discussion on django-developers: http://groups.google.com/group/django-developers/browse_thread/thread/65aabb45687e572e. This includes discussion about how to flush settings. Also related is ticket #14628.

comment:3 Changed 6 years ago by Claude Paroz

I'm probably not the best person to improve the patch as I'm not expert in decorators. Hopefully someone more skilled than me could help here. I'm available though to browse current tests to migrate to the new functions.

comment:4 Changed 6 years ago by Łukasz Rekucki

Needs documentation: set
Owner: changed from nobody to Łukasz Rekucki

comment:5 Changed 6 years ago by Luke Plant

Type: New feature

comment:6 Changed 6 years ago by Luke Plant

Severity: Normal

comment:7 Changed 6 years ago by Ramiro Morales

Easy pickings: unset

A context manager version of this functionality was added in r16165.

comment:8 Changed 6 years ago by Jannis Leidel

Oops, didn't know this ticket existed. I suppose we could additionally add a decorator to do the same as the context manager.

comment:9 Changed 6 years ago by Claude Paroz

I hesitated to close this one when I saw the work of jezdez. But after reading the code, I think that there still might be use cases for decorators.

comment:10 Changed 6 years ago by Jannis Leidel

Needs tests: set

Agreed, but the patch needs to use the same technique the TestCase.settings CM uses (using UserSettingsHandler) since that'll make sure that the previous settings instance is reset correctly.

Changed 6 years ago by Jannis Leidel

Attachment: 15561.2.diff added

with_settings decorator/context manager combo

Changed 6 years ago by Jannis Leidel

Attachment: 15561.3.diff added

Renamed to override_settings

Changed 6 years ago by Jannis Leidel

Attachment: 15561.4.diff added

Extended docs.

comment:11 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16237]:

Fixed #15561 -- Extended test setting override code added in r16165 with a decorator and a signal for setting changes.

comment:12 Changed 5 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

Note: See TracTickets for help on using tickets.
Back to Top