Skip to content

Commit

Permalink
imports optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderankin committed Sep 27, 2024
1 parent 1e3d77e commit c80f8d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions modules/postgres/testcontainers/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from time import sleep
from typing import Optional

from testcontainers.core.config import testcontainers_config as c
from testcontainers.core.generic import DbContainer
from testcontainers.core.utils import raise_for_deprecated_parameter
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs
from testcontainers.core.waiting_utils import wait_container_is_ready

_UNSET = object()

Expand Down Expand Up @@ -92,6 +90,12 @@ def get_connection_url(self, host: Optional[str] = None, driver: Optional[str] =
@wait_container_is_ready()
def _connect(self) -> None:
escaped_single_password = self.password.replace("'", "'\"'\"'")
result = self.exec(["sh", "-c", f"PGPASSWORD='{escaped_single_password}' psql --username {self.username} --dbname {self.dbname} --host 127.0.0.1 -c 'select version();'"])
result = self.exec(
[
"sh",
"-c",
f"PGPASSWORD='{escaped_single_password}' psql --username {self.username} --dbname {self.dbname} --host 127.0.0.1 -c 'select version();'",
]
)
if result.exit_code:
raise ConnectionError("pg_isready is not ready yet")
2 changes: 1 addition & 1 deletion modules/postgres/tests/test_postgres.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pathlib import Path

import pytest
import sqlalchemy

from testcontainers.postgres import PostgresContainer
import sqlalchemy


# https://www.postgresql.org/support/versioning/
Expand Down

0 comments on commit c80f8d5

Please sign in to comment.