New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preferred use of SimpleTestCase.settings() and SimpleTestCase.modify_settings(). #17690
base: main
Are you sure you want to change the base?
Conversation
(I was torn by the first commit. It's very straightforward, but is documented, so I guess we should do a ticket?) |
@ngnpope Thanks 👍 It's hard for me to understand why it's worth changing. |
Indeed, but it is also presented earlier in the documentation than the global decorator function and caught me out because it didn't work in a class-level scope as I naively assumed it might.
Also true. The advantage of the shortcut is that it avoids the need to import the decorator function in some cases. |
…tatic methods. These can be static because they do not depend on anything from the instance or class. Doing so means that they can be used from other class methods, e.g. `.setUpClass()`.
df272b2
to
a004efb
Compare
I've reviewed this work and I agree that having Having said that, I did wonder while reading the diff what's the point of providing |
If we're keeping these shortcuts then, yes, this makes sense.
It's not really style-ish refactoring. It's arguably using the preferred approach, given the methods on the test case class are documented ahead of the general functions...
No, there wasn't, but I see the appeal in getting rid of them - they're partially flawed without the first commit above, and the most common use is as a decorator on the test method or test case class in cases where the override isn't dynamic. Really they only benefit they provide is not needing the import, but that is rare because the more useful, more common decorator usage requires the import.
It seems that Here are some naive counts of usage in Django itself: $ git grep -hc @override_settings | paste -s -d+ - | bc
1224
$ git grep -hc @modify_settings | paste -s -d+ - | bc
83
$ git grep -hc 'self.settings(' | paste -s -d+ - | bc
274
$ git grep -hc 'self.modify_settings(' | paste -s -d+ - | bc
13 So, do we want to make this less TIMTOWTDI and deprecate? |
@ngnpope Hi and thank you for your patience. I've been thinking about this, and while I like the idea of the cleanup, I wonder how invasive it could be for many code bases out there. Would you be willing to propose this in the forum to get a sense of the overall acceptance/rejection of the cleanup idea? /remind me to check on this in one month |
@nessita set a reminder for 4/19/2024 |
👋 @nessita, check on this |
I've continued my thinking about this and I do believe now that we should not remove |
Thanks for the follow up @nessita. So, I agree that the first commit makes sense as it makes the methods on Certainly we can ignore the other two commits - my opinion changed. Even if we don't want to go in the opposite direction, however, and deprecate these methods, I think we should perhaps invert the documentation order to promote the decorators first as they can be used more flexibly (in more contexts) than the methods can. |
I think I agree. The docs could use a minor refactor to present the helpers in a way where the Wanna give it a try @ngnpope? /remind me about this in one month |
@nessita set a reminder for 5/22/2024 |
Nothing fresh to offer, commit 1 and inverting the documentation makes sense to me 👍 |
Following on from #17673, I noticed that we could make more use of
SimpleTestCase.settings()
andSimpleTestCase.modify_settings()
. By making them static methods, we can also use them in.setUpClass()
, etc. where appropriate.