Opened 4 years ago

Closed 4 years ago

#15081 closed (duplicate)

When running tests you cannot use data that is inserted the <app>/sql/model.sql

Reported by: maesjoch Owned by: nobody
Component: Testing framework Version: 1.2
Severity: Keywords: custom sql
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by russellm)

Consider following case:

#model

class sqltest(models.Model):
    
    name = models.CharField(max_length=100, unique=True)

#test

from django.test import TestCase
from testapp.app_test.models import sqltest

class SimpleTest(TestCase):
    def test_basic_addition(self):
        s = sqltest.objects.get(name='test1')
        self.assertTrue(s)

#in <app>/sql/sqltest.py

insert into app_test_sqltest (name) values ('test1');
insert into app_test_sqltest (name) values ('test2');
insert into app_test_sqltest (name) values ('test3');

When running your tests will not find the test1 entry. This is not consistent with how django docs explain it (although not that much testing information on custom sql).

Was this by design or is it an actual bug I do not know.

Change History (5)

comment:1 Changed 4 years ago by russellm

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I can't reproduce this. The test described passes as expected for me under SQLite and Postgres.

comment:2 Changed 4 years ago by russellm

  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted

Following more detail on IRC: This only affects MySQL.

comment:3 Changed 4 years ago by maesjoch

  • Triage Stage changed from Accepted to Unreviewed

I can reproduce with 'ENGINE': 'django.db.backends.postgresql_psycopg2',
Same app.

comment:4 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

I've already accepted the ticket. There's no need to move it back for another review.

comment:5 Changed 4 years ago by russellm

  • Resolution set to duplicate
  • Status changed from reopened to closed

Turns out this is already caught by Django's test suite, and has been reported as #14661,

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