#30295: MaxLengthORMTests.test_custom_max_lengths test fails when run in 
isolation
------------------------------------------------+------------------------
               Reporter:  Matt McDonald         |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Uncategorized         |        Version:  master
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  1
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 Attempting to run tests from the `max_lengths` tests package results in
 the following failure:

 {{{
 $ ./tests/runtests.py max_lengths  --verbosity=2
 Testing against Django installed in '/home/me/Development/django/django'
 with up to 12 processes
 Importing application max_lengths
 Skipping setup of unused database(s): default, other.
 System check identified no issues (0 silenced).
 ..E
 ======================================================================
 ERROR: test_custom_max_lengths (max_lengths.tests.MaxLengthORMTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
     yield
   File "/usr/lib/python3.6/unittest/case.py", line 605, in run
     testMethod()
   File "/home/me/mmcdonald/Development/django/tests/max_lengths/tests.py",
 line 38, in test_custom_max_lengths
     p = PersonWithCustomMaxLengths.objects.create(**new_args)
   File "/home/me/Development/django/django/db/models/manager.py", line 82,
 in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File "/home/me/Development/django/django/db/models/query.py", line 421,
 in create
     obj.save(force_insert=True, using=self.db)
   File "/home/me/Development/django/django/db/models/base.py", line 741,
 in save
     force_update=force_update, update_fields=update_fields)
   File "/home/me/Development/django/django/db/models/base.py", line 779,
 in save_base
     force_update, using, update_fields,
   File "/home/me/Development/django/django/db/models/base.py", line 870,
 in _save_table
     result = self._do_insert(cls._base_manager, using, fields, update_pk,
 raw)
   File "/home/me/Development/django/django/db/models/base.py", line 908,
 in _do_insert
     using=using, raw=raw)
   File "/home/me/Development/django/django/db/models/manager.py", line 82,
 in manager_method
     return getattr(self.get_queryset(), name)(*args, **kwargs)
   File "/home/me/Development/django/django/db/models/query.py", line 1175,
 in _insert
     return query.get_compiler(using=using).execute_sql(return_id)
   File "/home/me/Development/django/django/db/models/sql/compiler.py",
 line 1316, in execute_sql
     cursor.execute(sql, params)
   File "/home/me/Development/django/django/db/backends/utils.py", line 67,
 in execute
     return self._execute_with_wrappers(sql, params, many=False,
 executor=self._execute)
   File "/home/me/Development/django/django/db/backends/utils.py", line 76,
 in _execute_with_wrappers
     return executor(sql, params, many, context)
   File "/home/me/Development/django/django/db/backends/utils.py", line 84,
 in _execute
     return self.cursor.execute(sql, params)
   File "/home/me/Development/django/django/db/utils.py", line 89, in
 __exit__
     raise dj_exc_value.with_traceback(traceback) from exc_value
   File "/home/me/Development/django/django/db/backends/utils.py", line 84,
 in _execute
     return self.cursor.execute(sql, params)
   File "/home/me/Development/django/django/db/backends/sqlite3/base.py",
 line 391, in execute
     return Database.Cursor.execute(self, query, params)
 django.db.utils.OperationalError: no such table:
 max_lengths_personwithcustommaxlengths

 ----------------------------------------------------------------------
 Ran 3 tests in 0.122s

 FAILED (errors=1)
 }}}

 From a cursory glance, this appears to be a result of the
 `max_lengths.tests.MaxLengthORMTests` class inappropriately extending from
 `unittest.TestCase` when it should extend from `django.test.TestCase`, as
 the `test_custom_max_lengths` method relies upon database and table
 creation having been performed.

 Interestingly, when executed as as part of a run of the full test suite,
 the failure does not seem to occur. My guess would be that the test case
 is being grouped into a suite with at least one other test case inheriting
 from `django.test.TestCase`, which implicitly provides the database
 initialization required by the `max_lengths` test instead of skipping the
 db setup when the test is run in isolation.

 
https://github.com/django/django/blob/398afba084679f1055926f6f91bd33fe124a92c5/django/test/runner.py#L606

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30295>
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/049.0a794b563233dc4574a983f57d2e4f23%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to