#23841: TestCase.assertWarns doesn't work when using django's test runner.
----------------------------+--------------------
     Reporter:  Matt3o12    |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Python 3    |    Version:  1.6
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 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

--
Ticket URL: <https://code.djangoproject.com/ticket/23841>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.9971f4e8e53f5fe1336cef1bb2c7c34b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to