﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23841	TestCase.assertWarns doesn't work when using django's test runner.	Matt3o12	nobody	"Django's test runner (python manage.py test) doesn't seem to be supporting TestCase.assertWarns using a freshly created project. 
There is a testcase where django fails:


{{{
from unittest.case import TestCase
import warnings

class TestWarning(TestCase):
    def testAssertWarns(self):
        # should just pass

        with self.assertWarns(UserWarning):
            warnings.warn(""Hello world."", UserWarning)

    def testAssertWarnsRegex(self):
        with self.assertWarnsRegex(UserWarning, ""Hello world\.""):
            warnings.warn(""Hello world."")
}}}

When I run `$ python manage.py test`, I always end up getting:

{{{
======================================================================
ERROR: testAssertWarns (myapp.tests.TestWarning)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/private/tmp/djago/myproj/myapp/tests.py"", line 9, in testAssertWarns
    with self.assertWarns(UserWarning):
  File ""/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py"", line 205, in __enter__
    for v in sys.modules.values():
RuntimeError: dictionary changed size during iteration

======================================================================
ERROR: testAssertWarnsRegex (myapp.tests.TestWarning)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/private/tmp/djago/myproj/myapp/tests.py"", line 13, in testAssertWarnsRegex
    with self.assertWarnsRegex(UserWarning, ""Hello world\.""):
  File ""/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py"", line 205, in __enter__
    for v in sys.modules.values():
RuntimeError: dictionary changed size during iteration

----------------------------------------------------------------------
}}}

When I just run `$ python -m unittest`, these two tests pass. I've tested that on django 1.6 (using python 3.3) and django 1.7 (using python 3.3 and 3.4) and "	Bug	closed	Python 3	1.6	Normal	fixed		t.chaumeny@…	Unreviewed	0	0	0	0	0	0
