Opened 13 years ago

Closed 13 years ago

#16593 closed Cleanup/optimization (fixed)

Quick fix for proxy_model_inheritance tests

Reported by: Jim Dalton Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Jim Dalton Triage Stage: Unreviewed
Has patch: no Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: yes UI/UX: no

Description

The error I just now reported in #16592 revealed another fairly minor problem with the proxy_model_inheritance tests which should be easy to fix.

The test is exercising the syncdb command and then verifying the existence of certain tables. However, the call to syncdb is being made in the setUp() method instead of the test case itself. As a result, if there is an error when executing it (as happens with #16592), the tearDown() method is not called. This means the remainder of the test suite will be executed with a modified sys.path and settings.INSTALLED_APPS. Sure enough, this causes some other unrelated failures which do not occur when the tests are run in isolation.

Reproduce it with:

$ ./runtests.py --settings=testproject.settings unmanaged_models  proxy_model_inheritance bug8245
Creating test database for alias 'default'...
Creating test database for alias 'other'...
...EF
======================================================================
ERROR: test_table_exists (modeltests.proxy_model_inheritance.tests.ProxyModelInheritanceTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jsdalton/webs/testproject/src/django/tests/modeltests/proxy_model_inheritance/tests.py", line 25, in setUp
    call_command('syncdb', verbosity=0)
  File "/Users/jsdalton/webs/testproject/src/django/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/jsdalton/webs/testproject/src/django/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/Users/jsdalton/webs/testproject/src/django/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/Users/jsdalton/webs/testproject/src/django/django/core/management/commands/syncdb.py", line 121, in handle_noargs
    custom_sql = custom_sql_for_model(model, self.style, connection)
  File "/Users/jsdalton/webs/testproject/src/django/django/core/management/sql.py", line 150, in custom_sql_for_model
    app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql'))
  File "/Users/jsdalton/webs/testproject/src/django/django/db/models/loading.py", line 151, in get_app
    raise ImproperlyConfigured("App with label %s could not be found" % app_label)
ImproperlyConfigured: App with label unmanaged_models could not be found

======================================================================
FAIL: test_bug_8245 (regressiontests.bug8245.tests.Bug8245Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jsdalton/webs/testproject/src/django/tests/regressiontests/bug8245/tests.py", line 18, in test_bug_8245
    'autodiscover should have raised a "Bad admin module" error.')
AssertionError: autodiscover should have raised a "Bad admin module" error.

----------------------------------------------------------------------
Ran 5 tests in 2.417s

FAILED (failures=1, errors=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

That second failure seems to be caused by the test structure.

The attached patch moves the call where it should be (part of the test case) and resolves the issue. A minor cleanup, but will save other developers time in the future if a regression occurs.

Attachments (1)

proxy_model_inheritance_text_fix.v1.diff (1.1 KB ) - added by Jim Dalton 13 years ago.

Download all attachments as: .zip

Change History (2)

comment:1 by Ramiro Morales, 13 years ago

Resolution: fixed
Status: newclosed

In [16593]:

Fixed #16593 -- Refactored proxy_model_inheritance fixture setup to minimize the chances of leaving a modified INSTALLED_APPS setting for tests ran after it if setUp fails. Thanks Jim Dalton for the report and patch.

Note: See TracTickets for help on using tickets.
Back to Top