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
fix: pass doctests, s/doctest/doctests/, run them in gha, s/asyncpg/psycopg/ in doctest, fix keycloak flakiness: wait for first user (#505)
Doctests are run as interpreted code from docstrings. In order to run
these tests, libraries need to be available for the example code, and
usage of async code either needs to be wrapped in an `asyncio` call or
avoided completely.
This PR fixes up all failing doctests and makes `make doctests` target
run successfully again.
Summary:
- Renames Make target `doctest` to `doctests` to follow naming
convention from `tests` target
- Adds `doctests` step to Github Action workflow runs
- Replaces `asyncpg` example from `index.rst` with `psycopg` to be able
to run as a doctest. Also added `psycopg` as dev dependency (`asyncpg`
was already missing from here)
- Fixes Keycloak doctest by providing expected output, also did the same
for regular test
- Also: Fixed `wait_for_container` method in `Keycloak` module to
actually wait for the first user to be created (in order to be able to
authenticate at all) before returning the started container, if the
command is `dev-start`. This is needed in order to prevent race
conditions in flaky tests and for the sample usage code.
The snippet above will spin up the current latest version of a postgres database in a container. The :code:`get_connection_url()` convenience method returns a :code:`sqlalchemy` compatible url (using the :code:`psycopg2` driver per default) to connect to the database and retrieve the database version.
59
58
60
59
.. doctest::
61
60
62
-
>>> import asyncpg
63
61
>>> from testcontainers.postgres import PostgresContainer
62
+
>>> import psycopg
64
63
65
64
>>> with PostgresContainer("postgres:16", driver=None) as postgres:
66
-
... psql_url = container.get_connection_url()
67
-
... with asyncpg.create_pool(dsn=psql_url,server_settings={"jit": "off"}) as pool:
This snippet does the same, however using a specific version and the driver is set to None, to influence the :code:`get_connection_url()` convenience method to not include a driver in the URL (e.g. for compatibility with :code:`psycopg` v3).
73
73
74
-
Note, that the :code:`sqlalchemy` and :code:`psycopg2` packages are no longer a dependency of :code:`testcontainers[postgres]` and not needed to launch the Postgres container. Your project therefore needs to declare a dependency on the used driver and db access methods you use in your code.
74
+
Note, that the :code:`sqlalchemy` and :code:`psycopg` packages are no longer a dependency of :code:`testcontainers[postgres]` and not needed to launch the Postgres container. Your project therefore needs to declare a dependency on the used driver and db access methods you use in your code.
0 commit comments