Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15561 closed New feature (fixed)

Factorize settings manipulation in tests

Reported by: claudep Owned by: lrekucki
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 claudep 4 years ago.
Add settings manipulation functions in django test utilities
15561-i18n-tests.diff (11.3 KB) - added by claudep 4 years ago.
As an example, apply new test utils to i18n tests
15561.2.diff (12.2 KB) - added by jezdez 4 years ago.
with_settings decorator/context manager combo
15561.3.diff (12.3 KB) - added by jezdez 4 years ago.
Renamed to override_settings
15561.4.diff (14.9 KB) - added by jezdez 4 years ago.
Extended docs.

Download all attachments as: .zip

Change History (17)

Changed 4 years ago by claudep

Add settings manipulation functions in django test utilities

Changed 4 years ago by claudep

As an example, apply new test utils to i18n tests

comment:1 Changed 4 years ago by russellm

  • milestone set to 1.4
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by lrekucki

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 4 years ago by claudep

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 4 years ago by lrekucki

  • Needs documentation set
  • Owner changed from nobody to lrekucki

comment:5 Changed 4 years ago by lukeplant

  • Type set to New feature

comment:6 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:7 Changed 4 years ago by ramiro

  • Easy pickings unset

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

comment:8 Changed 4 years ago by jezdez

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 4 years ago by claudep

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 4 years ago by jezdez

  • 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 4 years ago by jezdez

with_settings decorator/context manager combo

Changed 4 years ago by jezdez

Renamed to override_settings

Changed 4 years ago by jezdez

Extended docs.

comment:11 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16237]:

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

comment:12 Changed 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

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