#19546 closed Cleanup/optimization (fixed)
Add logging configuration to test_sqlite.py
Reported by: | Anton Baklanov | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I am not able to see deprecation warnings while running tests with python 2.7. Adding -Wd and -Wall parameters has no effect either.
And only after adding py.warnings
logger i finally got my warnings. So i'm proposing to add this logger into 'default' django test config like that.
It may help to prevent commits like this one.
Attachments (2)
Change History (23)
comment:1 by , 12 years ago
Patch needs improvement: | set |
---|
comment:3 by , 12 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
I do think also that this is a serious problem if DeprecationWarning
are not shown when running tests, whether for Django itself or for any Django app.
I'd go even further and propose to modify the DjangoTestSuiteRunner
so as DeprecationWarnings
are on by default (they can still be hidden when running test with verbosity=0
).
by , 12 years ago
Attachment: | 19546.diff added |
---|
comment:4 by , 12 years ago
@claudep you are right, they (warnings) need to be shown independently of current settings and loggers.
And your patch looks like RFC for me.
comment:5 by , 12 years ago
Is this related to #18985 and [44046e8a38]?
If it is, is it enough to fix the problem in the test suite?
comment:6 by , 12 years ago
Yes it is related. In #18985, we fixed the issue when running the development server and DEBUG=True. But tests are generally running with DEBUG=False, hence the warnings are filtered out by the standard logging configuration.
comment:7 by , 12 years ago
Needs tests: | set |
---|
Makes sense. As far as I can tell, the patch just needs a test.
by , 12 years ago
Attachment: | 19546-2.diff added |
---|
comment:8 by , 12 years ago
I've attached a revised patch.
The setup for the logging tests now has a convoluted setup to NOT show the test deprecation during normal test runs. Because the warning and logging state is global, it is hard to test that our expected situation of capturing deprecations is working as expected, and at the same time show deprecations in tests, without polluting the test runner output every time with this test - so the setup saves and restores all streams.
The test runner takes some extreme steps to restore global state after running - this could be going too far for what is likely to be a single process running once?
The test for this patch uses machinery with a lot of overhead and takes between 1 and 2 seconds to run on my machine :(
I'm going to hold off on committing this for at least part of a day in case anyone can offer suggestions to the above shortcomings.
follow-up: 10 comment:9 by , 12 years ago
Would it be easier to capture stderr entirely?
from StringIO import StringIO # needs Python 3 compatible import import sys new_stderr = StringIO() old_stderr, sys.stderr = sys.stderr, new_stderr try: warnings.warn('Foo Deprecated', DeprecationWarning) self.assertIn('Foo Deprecated', output.getvalue()) finally: sys.stderr = old_stderr
comment:10 by , 12 years ago
Replying to aaugustin:
Would it be easier to capture stderr entirely?
I had tried that with a local instance of DjangoTestSuiteRunner - but invoking it's run_tests method inside a test proved too thorny and I went the admin scripts route.
unittest does something funky to capture/store the original stderr stream at least for warnings before running the test, even before the setUp method - I find this surprising, but can't explain why this strategy doesn't work
so the straightforward way to attempt this isn't working, this gist represents my increasingly verbose attempt - which does not work:
https://gist.github.com/4444864
I know some would say 1-2 seconds isn't that long - but I still find that a sort of painful addition.
comment:11 by , 12 years ago
so in trying to wrap this up - I've simplified the patch to be a little less engineered and just assume that stdlib global state is likely as it would be set by LazySettings
https://github.com/ptone/django/compare/ticket/19546
but am getting a fair of unwanted deprecation warning noise now when running the tests under py3
https://gist.github.com/6d384b4110fd916d1fd2
The source and solution to these warnings (and why they are py3 only) I haven't yet had time to fully investigate.
comment:12 by , 12 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
This looks good to me. I just fixed some of the deprecation warnings. I think this is a good sign that your patch is successful :-)
comment:13 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
hm, looks like some logging related tests are failing with this patch.