You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using pytest-django and pytest-docker; pretty sure my issue is with pytest-django but wanted to mention that.
Any tests I run that enable a database connection using the db fixture or @pytest.mark.django_db mark error with django.db.utils.OperationalError: connection is bad: nodename nor servname provided, or not known. I can run the test container fine, and a basic fixture I am using to wait to run tests until the application is running also works. I am running my migrations in an entrypoint script; I can see from Docker Desktop logs that they are running correctly. The entrypoint also ensures that the Django container waits for Postgres to be available before trying to run the migrations or server. I can see that http_service fixture which waits for Django to be available before running tests is succeeding, so Django itself seems to be running correctly (returns a 200 when visiting the root of the site and a 404 for a non-existent URL). But any tests which use pytest.mark.django_db error out. I'm not finding much for this connection is bad error; the RuntimeWarning is confusing, as the container runs fine and I can exec in and run the exact same commands as my test without issue.
E django.db.utils.OperationalError: connection is bad: nodename nor servname provided, or not known
../amendvenv/lib/python3.11/site-packages/psycopg/connection.py:728: OperationalError
------------------------------------------------------------------------------------------------------------------------------------ Captured stdout setup ------------------------------------------------------------------------------------------------------------------------------------
<Response [404]>
------------------------------------------------------------------------------------------------------------------------------------ Captured stderr setup ------------------------------------------------------------------------------------------------------------------------------------
Creating test database for alias 'default' ('test_amend')...
====================================================================================================================================== warnings summary =======================================================================================================================================
tests/unit/test_data.py::test_insert_state
/Users/colecrawford/GitHub/amendments-project/amendvenv/lib/python3.11/site-packages/django/db/backends/postgresql/base.py:405: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================================================================================== short test summary info ===================================================================================================================================
ERROR tests/unit/test_data.py::test_insert_state - django.db.utils.OperationalError: connection is bad: nodename nor servname provided, or not known
====================================================================================================================== 1 passed, 1 warning, 1 error in 107.75s (0:01:47) ======================================================================================================================
The text was updated successfully, but these errors were encountered:
I am using
pytest-django
andpytest-docker
; pretty sure my issue is withpytest-django
but wanted to mention that.Any tests I run that enable a database connection using the
db
fixture or@pytest.mark.django_db
mark error withdjango.db.utils.OperationalError: connection is bad: nodename nor servname provided, or not known
. I can run the test container fine, and a basic fixture I am using to wait to run tests until the application is running also works. I am running my migrations in an entrypoint script; I can see from Docker Desktop logs that they are running correctly. The entrypoint also ensures that the Django container waits for Postgres to be available before trying to run the migrations or server. I can see thathttp_service
fixture which waits for Django to be available before running tests is succeeding, so Django itself seems to be running correctly (returns a 200 when visiting the root of the site and a 404 for a non-existent URL). But any tests which usepytest.mark.django_db
error out. I'm not finding much for thisconnection is bad
error; theRuntimeWarning
is confusing, as the container runs fine and I canexec
in and run the exact same commands as my test without issue.The text was updated successfully, but these errors were encountered: