1

So, I get the following output while running the tests for my Django project:

WARNING 2013-04-25 17:55:29,977 18482 29789392 py.warnings:3 <module>() /home/sean/dev/project/testenv/local/lib/python2.7/site-packages/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
  DeprecationWarning)

WARNING 2013-04-25 17:55:29,986 18482 29789392 py.warnings:10 <module>() /home/sean/dev/project/testenv/local/lib/python2.7/site-packages/django/utils/copycompat.py:10: DeprecationWarning: django.utils.copycompat is deprecated; use the native copy module instead
  DeprecationWarning)

I'd like to figure out where in my code, or in what dependencies, these are originating.

http://docs.python.org/2/library/warnings.html

According to this, I can do the following to make Warnings be thrown as Exception and get a traceback:

At the top of my manage.py, before any other code is called:

import warnings
warnings.filterwarnings(
        'error', r".*",
        Warning, r'.*')

This causes "PendingDeprecationWarning: django.utils.simplejson is deprecated; use json instead." to be thrown, so I used:

import warnings
warnings.filterwarnings(
        'error', r".*",
        Warning, r'.*')
warnings.filterwarnings(
        'ignore', r".*",
        Warning, r'django\.utils\.simplejson')

But it's still printing out the previous DeprecationWarnings and not raising them as errors like it's supposed to.

Edit: Also, I tried putting print and pdb statements at the beginning of warnings.warn_explicit(), the place where the filter logic happens, and they never get called.

4

1 回答 1

1

You could run the tests or the local django server with the -W error option:

$ python -W error manage.py runserver

or

$ python -W error manage.py test

That will treat warnings as errors.

于 2013-11-12T18:22:49.757 回答