#23841 closed Bug (fixed)
TestCase.assertWarns doesn't work when using django's test runner.
Reported by: | Matt3o12 | Owned by: | nobody |
---|---|---|---|
Component: | Python 3 | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | t.chaumeny@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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
Change History (2)
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I'm closing this ticket as six upgrade to 1.8.0 has been backported to Django 1.6 (see https://github.com/django/django/commit/81477c91f68d7091f8da417a030dd4b9b776b70a). Upgrading Django will most likely resolve your problem.
This seems to be related https://bitbucket.org/gutworth/six/issue/68/assertwarns-and-six. six has been upgraded to 1.8.0 on master and I can't reproduce it (although I can with an older checkout).