I think django.test.ignore_warnings may meet your needs.

As for the latter idea, unless something is really eager to add a Python 2 
compatible version (if possible) to Django's SimpleTestCase, we can wait 
until dropping Python 2 support and then use the TestCase.assertWarns() in 
Python 3.2+.

On Sunday, April 3, 2016 at 6:21:59 AM UTC-4, Shai Berger wrote:
>
> Hi all, 
>
> While working on a ticket that had to do with cookies, I found myself 
> writing 
> this code (essentially): 
>
>         with warnings.catch_warnings(record=True) as warnings_log: 
>             # 
>             # Begin actual code I'm trying to test 
>             # 
>             CsrfViewMiddleware().process_view(req, token_view, (), {}) 
>             # 
>             # End actual code I'm trying to test 
>             # 
>         if (len(warnings_log) > 1 or 
>                 not issubclass(warnings_log[0].category, UnicodeWarning)): 
>             for warning in warnings_log: 
>                 warnings.warn(warning) 
>
> The code I'm trying to test is going to make a UnicodeWarning, because the 
> whole point of the test is to see how the code deals with broken user 
> input. 
> Having to wrap it in 5 lines of unrelated code feels odd. 
>
> So I thought a context manager to suppress specific warnings in a block 
> might 
> be generally useful, and for tests, it may be even useful to have an 
> assertWarns -- an analog of assertRaises. 
>
> Opinions? 
>
> Thanks, 
>         Shai. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/79a74215-bd1e-4df4-a56f-2b485b94ee33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to