M
M
m0ody2015-04-11 12:59:54
Django
m0ody, 2015-04-11 12:59:54

How to create django models for tests?

I started to deal with testing in Django and the task arose to test the Aggregations, QuerySet, Managers, etc. written by me. For more convenient testing, I would like to create separate models only for tests and so that they do not fall into production. What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
U
un1t, 2015-04-11
@un1t

Firstly, in production, tests do not need to be run. And secondly, tests should be run in a separate database.
Check out pytest and django-pytest.
Here you can see test examples
https://bitbucket.org/ishalyapin/django-test-examp...

S
sim3x, 2015-04-11
@sim3x

About the variety of test types
https://events.yandex.ru/lib/talks/535/
Depending on the type - the need to use
the database varies ) on a DBMS with settings as close as possible to production
. For a unit - DB is needed only if ORM
factory_boy is being tested for
selenium unit tests for acceptance
www.tdd-django-tutorial.com/tutorial/1

A
Andrey K, 2015-04-11
@mututunus

factoryboy.readthedocs.org/en/latest

A
Alexander Pinkevich, 2015-04-11
@pinkevich

Use a different database for tests

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ':memory:'
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question