diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/inspectdb/tests.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 06eb2c82f8..6fd1778b55 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -6,7 +6,8 @@ from unittest import skipUnless from django.core.management import call_command from django.db import connection -from django.test import TestCase, skipUnlessDBFeature +from django.test import TestCase, mock, skipUnlessDBFeature +from django.utils.encoding import force_text from django.utils.six import PY3, StringIO from .models import ColumnTypes @@ -268,3 +269,17 @@ class InspectDBTestCase(TestCase): self.assertIn("big_int_field = models.BigIntegerField()", output) finally: connection.introspection.data_types_reverse = orig_data_types_reverse + + def test_introspection_errors(self): + """ + Introspection errors should not crash the command, and the error should + be visible in the output. + """ + out = StringIO() + with mock.patch('django.db.backends.base.introspection.BaseDatabaseIntrospection.table_names', + return_value=['nonexistent']): + call_command('inspectdb', stdout=out) + output = force_text(out.getvalue()) + self.assertIn("# Unable to inspect table 'nonexistent'", output) + # The error message depends on the backend + self.assertIn("# The error was:", output) |
