Wednesday, August 30, 2017

Re: How do you interact with the Django test database outside of tests?

I've figured it out! I was running my end-to-end tests in a class which inherited from TestCase. This cause all the database calls for that entire class to be run within a transaction, so I couldn't see the changes because the transaction was never allowed to finish. By switching the base class to TransactionTestCase, I was able to prevent this behavior.

On Friday, August 25, 2017 at 5:25:03 PM UTC-4, Kurt Wheeler wrote:
I am attempting to write end-to-end tests for my system. To do this I am running one container called "workers" as it would normally be run during development, i.e. not via a test runner. I have another container called "foreman" that is run via a test runner which sets up the tests, sends work to the "workers" container, and then make assertions about the work that has been done. These two containers coordinate/communicate via a messaging system (Celery) and the database (postgres). Therefore I am running the "foreman" tests with the `--keepdb` option so the test database doesn't get destroyed, then changing the settings for the "workers" container to use "test_<my_db_name>" .

According to the docs: The default test database names are created by prepending test_ to the value of each NAME in DATABASES. Therefore I think that my "workers" container should be using the same database as the "foreman", even though it is being run by a test runner. However my issue is that the "workers" can't find any of the database records inserted by the "foreman".

I've tried to debug this by using the postgresql CLI to connect to the test database, but even when I insert a record from the tests, enter an infinite loop (so no cleanup code whatsoever will be run), and then check the tables in the test database I do not see any records there.

Does anyone know why I cannot seem to find any evidence of the test database records from any interface other than an actively running test?

Thanks in advance. I'm happy to share more details if needed, my project is even open source so I can link the source code if someone wants to dig that deep.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c4d80cee-b324-4fa8-ada4-b237033656e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment