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
https://pytest-django.readthedocs.io/en/latest/database.html#reuse-db-reuse-the-testing-database-between-test-runs


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  
<https://www.redhat.com/en/topics/devops/what-is-ci-cd#:~:text=Hat%20can%20help-,Overview,accelerate%20the%20software%20development%20lifecycle>)
I suggest using GitHub actions (follow this tutorial 
<https://www.honeybadger.io/blog/django-test-github-actions/>) 

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


> On 23 Jun 2024, at 8:01 AM, Gabriel Soler <gso...@gmail.com> wrote:
> 
> 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 
> 
> -- 
> 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+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@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
>  
> <https://groups.google.com/d/msgid/django-users/a9265616-ef64-4dbf-ab89-2599cbd1cdf8n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/653F1441-794C-4E53-89D5-954CC6E21DCC%40momnt.com.

Reply via email to