adamchainz / django-perf-rec

Keep detailed records of the performance of your Django code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is django-perf-rec working with sqlite?

brunobord opened this issue · comments

I've tried to make django perf-rec work with a test environment that uses only sqlite database (it's easier to set-up) and I had a strange result.

Here's my test:

from django_perf_rec import TestCaseMixin as PerfTestCaseMixin
from app.models import MyModel

class TestCase(PerfTestCaseMixin, TestCase):
    pass

class PerfTest(TestCase):

    def test_foo(self):
        with self.record_performance():
            self.assertEqual(MyModel.objects.count(), 0)

The resulting YAML is:

PerfTest.test_foo:
- db: QUERY = u# - PARAMS = ()

Where do you think this might come from? should I edit some settings to have a usable output?

Django used to freeze sqlite queries as QUERY = ... PARAMS = ... because the sqlite driver didn't keep a history of queries, but this was updated in some more recent version. I think it was 1.8 or before. This project tests on 1.8 with sqlite iirc.

in the said test, I'm using Django==1.8.17 :/

all right: using this database backend, the output is way more informative.
What could eventually been done is:

  • to include this "test db backend" in the distribution (I had to copy the django-perf-rec/tests/django18_sqlite3_backend directory instead of simply import it),
  • at least document this special case and give a hint on how to run tests using Django 1.8.x + sqlite.

I'd welcome a PR to expose that backend... but unless your prod deployment is using sqlite my strong recommendation is to use the database you use in production for tests.