diff --git a/django/test/simple.py b/django/test/simple.py
index bf0219d..3bcfec1 100644
a
|
b
|
|
| 1 | import logging |
1 | 2 | import unittest as real_unittest |
| 3 | import warnings |
2 | 4 | |
3 | 5 | from django.conf import settings |
4 | 6 | from django.core.exceptions import ImproperlyConfigured |
… |
… |
class DjangoTestSuiteRunner(object):
|
365 | 367 | self.setup_test_environment() |
366 | 368 | suite = self.build_suite(test_labels, extra_tests) |
367 | 369 | old_config = self.setup_databases() |
| 370 | if self.verbosity > 0: |
| 371 | # duplicate some of the steps taken in logging configuration |
| 372 | # to insure that DeprecationWarnings are displayed on sys.stderr |
| 373 | # during testing regardless of the Python default in >2.6 |
| 374 | if logging._warnings_showwarning is None: |
| 375 | old_captureWarnings = False |
| 376 | logging.captureWarnings(True) |
| 377 | else: |
| 378 | old_captureWarnings = True |
| 379 | warnings.simplefilter("default", DeprecationWarning) |
| 380 | new_filter = warnings.filters[0] |
| 381 | logger = logging.getLogger('py.warnings') |
| 382 | handler = logging.StreamHandler() |
| 383 | logger.addHandler(handler) |
368 | 384 | result = self.run_suite(suite) |
| 385 | if self.verbosity > 0: |
| 386 | # make every effort to restore global logging and warning state |
| 387 | if warnings.filters[0] == new_filter: |
| 388 | warnings.filters.pop(0) |
| 389 | logger.removeHandler(handler) |
| 390 | if not old_captureWarnings: |
| 391 | logging.captureWarnings(False) |
369 | 392 | self.teardown_databases(old_config) |
370 | 393 | self.teardown_test_environment() |
371 | 394 | return self.suite_result(suite, result) |
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py
index f983894..b3d9f3b 100644
a
|
b
|
class WarningLoggerTests(TestCase):
|
93 | 93 | and captured to the logging system |
94 | 94 | """ |
95 | 95 | def setUp(self): |
| 96 | # this convoluted setup is to avoid printing this deprecation to |
| 97 | # stderr during test running - as the test runner forces deprecations |
| 98 | # to be displayed at the global py.warnings level |
96 | 99 | self.logger = logging.getLogger('py.warnings') |
97 | | self.old_stream = self.logger.handlers[0].stream |
| 100 | self.outputs = [] |
| 101 | self.old_streams = [] |
| 102 | for handler in self.logger.handlers: |
| 103 | self.old_streams.append(handler.stream) |
| 104 | self.outputs.append(StringIO()) |
| 105 | handler.stream = self.outputs[-1] |
98 | 106 | |
99 | 107 | def tearDown(self): |
100 | | self.logger.handlers[0].stream = self.old_stream |
| 108 | for i, handler in enumerate(self.logger.handlers): |
| 109 | self.logger.handlers[i].stream = self.old_streams[i] |
101 | 110 | |
102 | 111 | @override_settings(DEBUG=True) |
103 | 112 | def test_warnings_capture(self): |
104 | | output = StringIO() |
105 | | self.logger.handlers[0].stream = output |
106 | 113 | warnings.warn('Foo Deprecated', DeprecationWarning) |
107 | | self.assertTrue('Foo Deprecated' in force_text(output.getvalue())) |
| 114 | output = force_text(self.outputs[0].getvalue()) |
| 115 | self.assertTrue('Foo Deprecated' in output) |
108 | 116 | |
109 | 117 | def test_warnings_capture_debug_false(self): |
110 | | output = StringIO() |
111 | | self.logger.handlers[0].stream = output |
112 | 118 | warnings.warn('Foo Deprecated', DeprecationWarning) |
113 | | self.assertFalse('Foo Deprecated' in force_text(output.getvalue())) |
| 119 | output = force_text(self.outputs[0].getvalue()) |
| 120 | self.assertFalse('Foo Deprecated' in output) |
114 | 121 | |
115 | 122 | |
116 | 123 | class CallbackFilterTest(TestCase): |
diff --git a/tests/regressiontests/test_runner/deprecation_app/__init__.py b/tests/regressiontests/test_runner/deprecation_app/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/regressiontests/test_runner/deprecation_app/models.py b/tests/regressiontests/test_runner/deprecation_app/models.py
new file mode 100644
index 0000000..71a8362
-
|
+
|
|
| 1 | from django.db import models |
| 2 | |
| 3 | # Create your models here. |
diff --git a/tests/regressiontests/test_runner/deprecation_app/tests.py b/tests/regressiontests/test_runner/deprecation_app/tests.py
new file mode 100644
index 0000000..e676c3e
-
|
+
|
|
| 1 | import warnings |
| 2 | |
| 3 | from django.test import TestCase |
| 4 | |
| 5 | class DummyTest(TestCase): |
| 6 | def test_warn(self): |
| 7 | warnings.warn("warning from test", DeprecationWarning) |
| 8 | |
| 9 | |
diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
index c723f16..5e58388 100644
a
|
b
|
class Sqlite3InMemoryTestDbs(unittest.TestCase):
|
261 | 261 | db.connections = old_db_connections |
262 | 262 | |
263 | 263 | |
| 264 | class DeprecationDisplayTest(AdminScriptTestCase): |
| 265 | # tests for 19546 |
| 266 | def setUp(self): |
| 267 | settings = {'INSTALLED_APPS': '("regressiontests.test_runner.deprecation_app",)' } |
| 268 | self.write_settings('settings.py', sdict=settings) |
| 269 | |
| 270 | def tearDown(self): |
| 271 | self.remove_settings('settings.py') |
| 272 | |
| 273 | def test_runner_deprecation_verbosity_default(self): |
| 274 | args = ['test', '--settings=regressiontests.settings'] |
| 275 | out, err = self.run_django_admin(args) |
| 276 | self.assertTrue("DeprecationWarning: warning from test" in err) |
| 277 | |
| 278 | def test_runner_deprecation_verbosity_zero(self): |
| 279 | args = ['test', '--settings=regressiontests.settings', '--verbosity=0'] |
| 280 | out, err = self.run_django_admin(args) |
| 281 | self.assertFalse("DeprecationWarning: warning from test" in err) |
| 282 | |
264 | 283 | class AutoIncrementResetTest(TransactionTestCase): |
265 | 284 | """ |
266 | 285 | Here we test creating the same model two times in different test methods, |