Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26009 closed Bug (fixed)

contenttypes_tests fail when run in isolation

Reported by: Marten Kenbeek Owned by: nobody
Component: Testing framework Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Marten Kenbeek)

3 models in tests/order_with_respect_to/models.py are missing an explicit app_label.

$ python runtests.py --parallel=1 contenttypes_tests.test_order_with_respect_to
Testing against Django installed in '/vagrant/django/django'
Traceback (most recent call last):
  File "runtests.py", line 450, in <module>
    options.debug_sql, options.parallel)
  File "runtests.py", line 267, in django_tests
    extra_tests=extra_tests,
  File "/vagrant/django/django/test/runner.py", line 531, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/vagrant/django/django/test/runner.py", line 422, in build_suite
    tests = self.test_loader.loadTestsFromName(label)
  File "/usr/lib/python3.4/unittest/loader.py", line 105, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "/vagrant/django/tests/contenttypes_tests/test_order_with_respect_to.py", line 1, in <module>
    from order_with_respect_to.tests import (
  File "/vagrant/django/tests/order_with_respect_to/tests.py", line 9, in <module>
    from .models import Answer, Dimension, Entity, Post, Question
  File "/vagrant/django/tests/order_with_respect_to/models.py", line 48, in <module>
    class Entity(models.Model):
  File "/vagrant/django/django/db/models/base.py", line 102, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class order_with_respect_to.models.Entity doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Attachments (1)

26009.diff (966 bytes ) - added by Tim Graham 8 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Marten Kenbeek, 8 years ago

Description: modified (diff)

comment:2 by Simon Charette, 8 years ago

What about preventing contenttypes_tests from importing models from another test application instead?

by Tim Graham, 8 years ago

Attachment: 26009.diff added

comment:3 by Tim Graham, 8 years ago

Easy pickings: unset
Has patch: set
Triage Stage: UnreviewedAccepted

Like the attached patch? I'm not too sure how proper model sharing works between test apps.

comment:4 by Tim Graham, 8 years ago

Here is the commit that introduced it: 7bec480fe2ace94c8e7f0c88485442bfa74436b4

Maybe a better solution is to make tetts/order_with_respect_to/models.py into a module and separate the models that are reused and those that are not. This might allow specifying app_label on only the shared models. On other hand, if there's a reason why we shouldn't share models, then I guess we'll just have to copy the models and try to keep them in sync.

comment:5 by Marten Kenbeek, 8 years ago

contenttypes_tests/order_with_respect_to.py currently imports the testcases from order_with_respect_to/tests.py. We can factor out the functionality in those testcases into base testcases in a separate module, then you won't have to import those models in contenttypes_tests.

comment:6 by Tim Graham, 8 years ago

Okay, I've moved the shared tests to base_tests.py. There's a small design decision I commented about in the pull request.

comment:7 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 2c6c873e:

Fixed #26009 -- Fixed contenttypes_tests isolation.

comment:8 by Tim Graham <timograham@…>, 8 years ago

In 775291d:

[1.9.x] Fixed #26009 -- Fixed contenttypes_tests isolation.

Backport of 2c6c873e3fca6c0c54c2335e131f7742fcf2cf26 from master

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