#24658 closed Bug (fixed)
Schema tests fail when run in isolation
| Reported by: | Claude Paroz | Owned by: | vladiibine |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Because tables are deleted in tearDown, when running an individual test, the tables are still existing and any create_model operation fail.
Change History (8)
comment:1 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 11 years ago
comment:3 by , 11 years ago
| Resolution: | → needsinfo |
|---|---|
| Status: | assigned → closed |
comment:4 by , 11 years ago
Also, I ran this on both the 1.8 branch, and the master on the commit f043434174db3432eb63c341573c1ea89ef59b91, with Python version Python 2.7.5+
I'm releasing this ticket, so that someone else can take a look. If you provide more information, I'll check it out from time to time.
comment:5 by , 11 years ago
Claude, could you more details on which tests fail when run in isolation.
I couldn't reproduce with:
./runtests.py schema.tests.SchemaTests --settings=test_postgres
or
./runtests.py schema.tests.SchemaTests.test_creation_deletion
or
./runtests.py schema.tests.SchemaTests.test_creation_deletion schema.tests.SchemaTests.test_fk --settings=test_postgres
comment:6 by , 11 years ago
I found the issue. The problem happens only with tests using the Note model, and the cause is that the Note model misses the apps = new_apps Meta attribute. I'll fix that ASAP.
I've tried to test your scenario, but I think more information.
I dont know if I understood correctly, but I tried to run just one individual test, and use the SchemaEditor.create_model method to create a new model class, and instantiate it.
Here's my code, what works (I can create a dynamic model within the test and instantiate it - no errors)
from django.test import TestCase
from .models import MyModel class MyTestCase(TestCase): def test_1(self): from django.db import connection with connection.schema_editor() as editor: other_model = self.create_model(editor) my_model = MyModel.objects.create(name='foo') other_model_instance = other_model.objects.create(name='bar') def test_2(self): my_model = MyModel(name='baz') def tearDown(self): print '>>>inside tearDown' # super(MyTestCase, self).tearDown() def create_model(self, editor): from django.db import models class OtherModel(models.Model): name = models.CharField(max_length=30, blank=True) editor.create_model(OtherModel) return OtherModelThen from the command line, I ran the test suites with all 3 of these commands:
Please give more details on how you're getting this issue.