Heroku testing

49 views
Skip to first unread message

Gabriel Soler

unread,
Jun 23, 2024, 4:24:42 PM (9 days ago) Jun 23
to Django users
Dear all

I am doing my first deployment and using heroku. I am using the eco tier and connected a postgres database.
When I try to run tests with heroku CLI it tells me I am not allowed to create a database. As Django creates a database and destroys it after, I wonder how you have solved this issue.
I saw in a Ruby section the possibility of having a Dyno dB only for testing but couldn't find it. Another option seems to connect to the current database with some risks. A third option is to have a custom test database on its own. 
I don't know how to do this in Django form, please help :)
Gabriel 

Reddy Tintaya

unread,
Jun 23, 2024, 11:02:23 PM (9 days ago) Jun 23
to django...@googlegroups.com
Short answer:

Create your test db the same way you created the one that your application already uses.
Run your tests using the keep db flag: python manage.py test --keepdb or reuse-db in case you are using pytest


Long answer, do you really need to run tests on heroku?:
Running your tests on the same environment you have the production application is not a common approach, I don’t think you have enough reasons to do this. 
Usually you run your test in a different environment (the main reason is because you want to dedicate your server resources to only serve real client requests)

First I would split my environments by responsibility.
A common practice is to have different environments with different databases
- dev: usually your local, where you develop
- staging: exactly copy of prod environment where you only have tests users.
- prod environment: This is what your real users use

Define a CiI/CD process and make the tests part of it ( CI/CD process )
I suggest using GitHub actions (follow this tutorial

Leaving some links so you can do a further research, if you have any specific question just let me know :)


Congrats for deploying your firsts deployments!

Regards,
Reddy Tintaya


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a9265616-ef64-4dbf-ab89-2599cbd1cdf8n%40googlegroups.com.

Gabriel Soler

unread,
Jun 24, 2024, 1:40:01 PM (8 days ago) Jun 24
to Django users
Hi, thank you for the answer. It makes sense to create a second environment to not mess up (which has happened 😭). I accidentally lost sign up when setting up flat pages, because somehow the site pk got the number 3. And only happened in the production, so needed to find that in the shell. 
I thought having a test would help to know when something bad is happening.
I will try to make more dynos with same project.

Thanks

Gabriel 

Reply all
Reply to author
Forward
0 new messages