Answer the question
In order to leave comments, you need to log in
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
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...
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
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 questionAsk a Question
731 491 924 answers to any question