forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: reusable containers #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matthiasschaub
wants to merge
73
commits into
main
Choose a base branch
from
reusable_containers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65e70c8
to
d07e50a
Compare
44660f1
to
74c8df1
Compare
adresses testcontainers#109 Co-authored-by: Levi Szamek <[email protected]>
50e6160
to
e87e782
Compare
do not create Ryuk cleanup instance if reuse enabled and container has been start with `with_reuse`
🤖 I have created a release *beep* *boop* --- ## [4.9.1](testcontainers/testcontainers-python@testcontainers-v4.9.0...testcontainers-v4.9.1) (2025-01-21) ### Bug Fixes * milvus healthcheck: use correct requests errors ([testcontainers#759](testcontainers#759)) ([78b137c](testcontainers@78b137c)) * **mysql:** add dialect parameter instead of hardcoded mysql dialect ([testcontainers#739](testcontainers#739)) ([8d77bd3](testcontainers@8d77bd3)) * **tests:** replace dind-test direct docker usage with sdk ([testcontainers#750](testcontainers#750)) ([ace2a7d](testcontainers@ace2a7d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…estcontainers#769) When invoking `.start()` multiple times on the same `DockerContainer` instance, the call fails with `ValueError: The org.testcontainers namespace is reserved for internal use` error. Example code: ``` from testcontainers.core.container import DockerContainer container = DockerContainer("alpine:latest").with_kwargs(labels={}) container.start() container.stop() container.start() ``` The fix is to update labels for the container in a copy of the user-provided dictionary, so that: * the code doesn't mutate user structures * avoid side effects, allowing for multiple .start() invocations
Fixed a typo which I ran into while working a bugfix.
testcontainers#766) @alexanderankin We already discussed last year that we only want to support the latest Keycloak version. I added the `latest` tag to test parameterization so we get a better feedback for future Keycloak updates. Fixes testcontainers#764 --------- Co-authored-by: David Ankin <[email protected]>
…ers#773) This closes testcontainers#772 --------- Co-authored-by: David Ankin <[email protected]>
Make sure the test covers the intended behaviour. Previously it was executing the create_labels function without actually verifying there are no side effects.
use convention for getting ip and port instead of hardcoding DIND mode
🤖 I have created a release *beep* *boop* --- ## [4.9.2](testcontainers/testcontainers-python@testcontainers-v4.9.1...testcontainers-v4.9.2) (2025-02-26) ### Bug Fixes * Change env var disabling OpenSearch security plugin ([testcontainers#773](testcontainers#773)) ([2620d7f](testcontainers@2620d7f)) * **core:** create_label test ([testcontainers#771](testcontainers#771)) ([7517297](testcontainers@7517297)) * **core:** multiple container start invocations with custom labels ([testcontainers#769](testcontainers#769)) ([3e783a8](testcontainers@3e783a8)) * **keycloak:** Fixed Keycloak testcontainer for latest version v26.1.0 ([testcontainers#766](testcontainers#766)) ([b1642e9](testcontainers@b1642e9)) * **scylla:** scylla get cluster method ([testcontainers#778](testcontainers#778)) ([46913c1](testcontainers@46913c1)) ### Documentation * Fixed typo in CONTRIBUTING.md ([testcontainers#767](testcontainers#767)) ([f0bb0f5](testcontainers@f0bb0f5)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This will address the Security issue reported on testcontainers#786 As recommended, `tj-actions/changed-files` was replace replaced with [path-filter](https://github.com/dorny/paths-filter) --------- Co-authored-by: David Ankin <[email protected]>
Add new SocatContainer at testcontainers module that can be used along with other modules as a helper. --------- Co-authored-by: David Ankin <[email protected]>
The mongodb image was expired, [looks like it's support is now included on latest](Azure/azure-cosmos-db-emulator-docker#112) so aligning it with the other DBs types under cosmosdb
…estcontainers#828) Once the new docs site is up I will likely add a demo there, but for the moment a quick basic unit test to ensure both are properly working.
Chroma deprecated their v1 health check. Updated the version and module to use the new v2 endpoint.
…ent (testcontainers#814) I want to help contribute to testcontainers-python but issues getting the local environment running. Starting off with fixing the install + test suite so myself and other people on Mac can get up and running faster. Manual testing done: This branch was tested on a few different Mac machines the and a Linux VM (still on arm). `make install` and `make tests` checked in all envs, I also checked docs, build, and cleans on the Linux VM and a M2 mac. Notes: * Poetry markers aren't bullet proof, but works for ibm so it's good enough for now, else we'd need a more complex install and test build scripts (for dind tests) which I played around with but ended up removing to keep the PR smaller and less complex. * Skipping arm + mac specific tests in the test suite, these are testing either features that Macs don't have or the community module doesn't actually support macs. For the sake of contributors this shouldn't matter, the CI will still be testing everything fully. * Mac skip reasons given: I'm not deeply familiar with these community packages or the menewsha of mac docker vs other OS dockers. There might be better explanations for why it needed to be skipped. Ticket: testcontainers#813 --------- Co-authored-by: David Ankin <[email protected]>
Switches the Qdrant image tag to `latest` by default. This makes it easier to use new features like the [Batch Search API](https://qdrant.tech/documentation/concepts/search/#batch-search-api) without manually updating the version. The latest version is 1.13.5 as of today. You can still override the image if needed, but this keeps things simple and up to date by default. --------- Co-authored-by: David Ankin <[email protected]>
## PR Summary This small PR fixes the pika pypi reference in RabbitMqContainer class page. Relevant page: https://testcontainers-python.readthedocs.io/en/latest/modules/rabbitmq/README.html Signed-off-by: Emmanuel Ferdman <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [4.11.0](testcontainers/testcontainers-python@testcontainers-v4.10.0...testcontainers-v4.11.0) (2025-06-15) ### Features * **core:** Protocol support for container port bind and expose ([testcontainers#690](testcontainers#690)) ([a0d4317](testcontainers@a0d4317)) * DockerContainer initializer to accept its private members as kwargs ([testcontainers#809](testcontainers#809)) ([e7feb53](testcontainers@e7feb53)) ### Bug Fixes * **compose:** use provided docker command instead of default ([testcontainers#785](testcontainers#785)) ([0ae704a](testcontainers@0ae704a)) * **core:** Add kwargs to image build ([testcontainers#708](testcontainers#708)) ([cc02f94](testcontainers@cc02f94)) * **core:** change with_command type to include list of strings ([testcontainers#789](testcontainers#789)) ([f7c29cb](testcontainers@f7c29cb)) * **core:** Determine docker socket for rootless docker ([testcontainers#779](testcontainers#779)) ([6817582](testcontainers@6817582)) * **core:** Typing in docker_client ([testcontainers#702](testcontainers#702)) ([e8bf224](testcontainers@e8bf224)) * **core:** Typing in generic + network ([testcontainers#700](testcontainers#700)) ([2061912](testcontainers@2061912)) * **core:** Typing in version ([testcontainers#701](testcontainers#701)) ([9dc2a02](testcontainers@9dc2a02)) * **core:** wait in test core registry ([testcontainers#812](testcontainers#812)) ([b574c0e](testcontainers@b574c0e)) * **modules:** fix cosmosdb failure ([testcontainers#827](testcontainers#827)) ([dafcbed](testcontainers@dafcbed)) * **modules:** update chroma version ([testcontainers#826](testcontainers#826)) ([b7d41dd](testcontainers@b7d41dd)) * **rabbitmq:** correct pika pypi reference ([testcontainers#817](testcontainers#817)) ([e90d308](testcontainers@e90d308)) * **registry:** module typed ([testcontainers#811](testcontainers#811)) ([6b11268](testcontainers@6b11268)) * use connection mode override function in config ([testcontainers#775](testcontainers#775)) ([ab2a1ab](testcontainers@ab2a1ab)), closes [testcontainers#774](testcontainers#774) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
# Hello all! I've been working on getting a new and improved docs site for Testcontainers Python. This docs site aligns it with Testcontainers Java/Go/.NET/Node which will hopefully help users onboard and adopt Testcontainers more easily.  Testing fork deploys can be seen here, I'm also lining up the official builds to live on the python.testcontainers.org name space! 👀 https://exquisite-dusk-036c28.netlify.app/ ## Why? We (Docker) want to support the Python community! A big improvement opportunity I saw was the current docs site compared to some of the other languages. Adopting the same template and builds will help keep use inline with the other and hopefully make Testcontainers Python easier to adopt by providing a starting point with more guide style content. ## Usage and Details The old Sphinx site has been left untouched for now (TBD by the community if it's provided value imo). This is a large change for writing documentation on the lib. There is now a `/docs` folder filler with markdown files rather then being powered only by code comments. The left hand navigation is controlled by a new yml file on the root of the project called `mkdocs.yml`. Rather then using Sphinx to parse code comments, with mkdocs you can include example python files to go with the documentation. I've created community module usage examples beside their implementation called `example_basic.py` but people can make other example files in the source as well. The linter is ignoring files with `example_` in them to ease builds for the docs purposes (and missing dependencies that may not matter). In the documentation site you can them import your examples via ```text # MinIO ........ ## Usage example <!--codeinclude--> [Creating a MinIO container](../../modules/minio/example_basic.py) <!--/codeinclude--> ``` Content was largely generated by reading the source code with an editing pass from one of Docker's technical writers. ## Running / Editing the Docs Site Locally A new Testcontainer python docs Dockerfile lives in the root of the project which handles the docssite specific dependencies. The container will build and serve the site for you. `make serve-docs` ## How Documentation Will Deploy It's Netlify powered. We can configure it to do preview deploys per PR and deploy a new site on merge to main. Unfortunately Netlify doesn't support Poetry so to keep the builds simple there is a requirements.txt for explicitly the docs site dependency. ## The Contents of the New Documentation As mentioned briefly in the opening we used AI to help generate the content of the site by reading the source code, myself and Arthur also did some human passes to ensure things read well, but clearly more help from people ensuring the accuracy will come over time. Once the new docs site is merged into main and hosting is fully working **I think we should post in the community slack and ask for feedback**, the two docs sites will run concurrently before officially launching (replacing) the current docs site. --------- Co-authored-by: ArthurFlag <[email protected]>
…estcontainers#833) Make configuration monkeypatchable. Also show users how within readme. This should also fix the bug in testcontainers#830 and supersedes testcontainers#821 and testcontainers#832 --------- Co-authored-by: David Ankin <[email protected]>
makes mypy happier --------- Co-authored-by: Roy Moore <[email protected]>
fix testcontainers#763 --------- Co-authored-by: Roy Moore <[email protected]>
Just a tiny addition to make large configurations easier to do in code. --------- Co-authored-by: Roy Moore <[email protected]> Co-authored-by: David Ankin <[email protected]>
1. leftovers from a previous mypy refactor ```python core/testcontainers/core/config.py:42: error: Redundant cast to "str" [redundant-cast] socket_path = cast("str", socket_path) ``` Post fix: ```bash #poetry run mypy --config-file pyproject.toml core Success: no issues found in 36 source files ``` 2. add mypy check to the CI under lint, also create a simple report if something is wrong.
Add OpenFGA testcontainer module --------- Signed-off-by: Petr Fedchenkov <[email protected]> Co-authored-by: David Ankin <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [4.12.0](testcontainers/testcontainers-python@testcontainers-v4.11.0...testcontainers-v4.12.0) (2025-07-21) ### Features * **main:** New Testcontainers Python Docs Site ([testcontainers#822](testcontainers#822)) ([a6bdf0e](testcontainers@a6bdf0e)) * make config monkeypatchable, fix config related startup issues ([testcontainers#833](testcontainers#833)) ([ff6a32d](testcontainers@ff6a32d)) * **modules:** add OpenFGA module ([testcontainers#762](testcontainers#762)) ([0b7b482](testcontainers@0b7b482)) * set multiple variables via keyword args ([testcontainers#804](testcontainers#804)) ([1532df5](testcontainers@1532df5)) ### Bug Fixes * **core:** mypy ([testcontainers#810](testcontainers#810)) ([b816762](testcontainers@b816762)) * Enable mypy in the CI ([testcontainers#842](testcontainers#842)) ([ef65bd1](testcontainers@ef65bd1)) * just use the getLogger API and do not override logger settings ([testcontainers#836](testcontainers#836)) ([f467c84](testcontainers@f467c84)) ### Documentation * missing compose html from old docs ([testcontainers#776](testcontainers#776)) ([d749fc6](testcontainers@d749fc6)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Aligns testcontainers-python with the testcontainers community standard wait strategy pattern used across Java, Go, and other implementations. This provides a consistent developer experience and better maintainability. ## Examples From: ``` wait_for_logs(container, "Test Sample Image") ``` To: ``` from testcontainers.core.wait_strategies import LogMessageWaitStrategy container.waiting_for(LogMessageWaitStrategy("Server started")) ``` ## Backward Compatibility No breaking changes - all existing code continues working Deprecation warnings added to wait_for_logs() and @wait_container_is_ready Clear migration path provided in warning messages ### New: core/testcontainers/core/wait_strategies.py - Strategy implementations core/tests/test_wait_strategies*.py - Comprehensive test coverage ### Modified: core/testcontainers/core/container.py - Added waiting_for() method core/testcontainers/compose/compose.py - Added compose wait strategy support core/testcontainers/core/waiting_utils.py - Base classes and protocol ## Future Strategies to quickly follow Foundation enables community-standard wait strategies: HttpWaitStrategy, HealthcheckWaitStrategy, PortWaitStrategy, CompositeWaitStrategy ## Testing Unit tests with parameterized scenarios Integration tests with real Docker containers Protocol compliance verification Backward compatibility validation
…s#839) This config variable gets passed into `time.sleep`, which can work with ints and floats. Making this a float type allows polling intervals under a second, which can reduce startup times for containers that spin up very quickly. --------- Co-authored-by: David Ankin <[email protected]>
) It is useful to be able to pass a list of `env_file`s, especially since you can pass a list of `compose_file_name`s. Builds upon testcontainers#135, matching `compose_file_name`.
…ocal access (testcontainers#859) **Resolves testcontainers#851** This Pull Request enhances the `AzuriteContainer` to provide more flexible and robust connection strings, specifically enabling seamless communication between Azurite and other containers within the same Docker network. It also clarifies access from the local host, addressing the need for distinct connection types in containerized testing environments. --- ### Key Changes * **Introduces `ConnectionStringType` enum:** This new enum allows specifying the intended access pattern when requesting an Azurite connection string: * `NETWORK`: Optimized for inter-container communication, leveraging Docker network aliases for direct connectivity. * `LOCALHOST`: Designed for access from the host machine, utilizing dynamically exposed ports and the Docker host IP. * **Refactored `get_connection_string`:** The main method now dispatches to the appropriate internal function based on the `ConnectionStringType` provided. * **Improved `get_external_connection_string`:** This method has been enhanced to intelligently prioritize network aliases for inter-container communication and provide a robust fallback to the Docker host IP for other scenarios. * **Comprehensive Unit Test:** A new test case, `test_azurite_inter_container_communication_with_network_string`, has been added to thoroughly validate both network-based and local host-based connection string functionality. * **Enhanced Docstrings:** All relevant methods within `AzuriteContainer` and the associated example application (`network_container.py`) have received updated and more detailed docstrings for improved clarity and usage guidance. --- ### Testing To validate these functionalities, the new test case `test_azurite_inter_container_communication_with_network_string` was introduced. This test specifically verifies: * **Inter-container communication:** An external application container successfully connects to Azurite using the `NETWORK` connection string (via its network alias) and performs an operation (e.g., creates a blob container). * **Local host access verification:** The operation performed by the external container is then successfully verified from the local test machine using the `LOCALHOST` connection string, confirming data persistence and accessibility. --- ### Concerns and Questions As this is my first contribution to this repository, I've aimed for comprehensive docstrings and clear code. I'm open to feedback on their level of detail, adherence to project conventions, or any other aspect of the implementation. Please let me know if any further changes or clarifications are needed.
…ners#863) fix testcontainers#864 The environment variables were not overridden from the .testcontainers.properties file for ryuk variables. This causes the properties file to never actually be used. This commit detects the environment variable, and if unspecified falls back to the properties file, and if not specified, defaults to false --------- Co-authored-by: David Ankin <[email protected]>
- Add HttpWaitStrategy for HTTP endpoint waiting with TLS, auth, headers support - Add HealthcheckWaitStrategy for Docker health check status monitoring - Add PortWaitStrategy for TCP port availability checking - Add FileExistsWaitStrategy for filesystem file existence waiting - Add CompositeWaitStrategy for combining multiple wait conditions - Include comprehensive unit tests for all new strategies - Enhanced error messages with actionable hints for debugging - Maintain backward compatibility with existing LogMessageWaitStrategy - Fix mypy type annotations for all new wait strategies --------- Co-authored-by: David Ankin <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [4.13.0](testcontainers/testcontainers-python@testcontainers-v4.12.0...testcontainers-v4.13.0) (2025-08-27) ### Features * **azurite:** Enhance connection string generation for network and local access ([testcontainers#859](testcontainers#859)) ([b21e5e3](testcontainers@b21e5e3)) * **core:** add enhanced wait strategies ([testcontainers#855](testcontainers#855)) ([60d21f8](testcontainers@60d21f8)) * **core:** DockerCompose: support list of env_files ([testcontainers#847](testcontainers#847)) ([fe206eb](testcontainers@fe206eb)) ### Bug Fixes * assert-in-get_container_host_ip-before-start ([testcontainers#862](testcontainers#862)) ([fc4155e](testcontainers@fc4155e)) * **core:** improper reading of .testcontainers.properties ([testcontainers#863](testcontainers#863)) ([350f246](testcontainers@350f246)) * **core:** Make TC_POOLING_INTERVAL/sleep_time a float ([testcontainers#839](testcontainers#839)) ([a072f3f](testcontainers@a072f3f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
## Description `testcontainers-python` is not compatible with python 3.13 because of several packages. ## Related issues Fixes testcontainers#870 ## Packages update - bump cffi: python-cffi/cffi#24 - bump psycopg2: psycopg/psycopg2#1695 - bump trio: python-trio/trio#2955 - bump pytest: pytest-dev/pytest#12334 - bump pymilvus: milvus-io/pymilvus#2684 - bump twine: pypa/twine#1184 - bump cryptography: pyca/cryptography#11491 - bump greenlet: python-greenlet/greenlet@9497948 (python-greenlet/greenlet#392) - bump grpcio: grpc/grpc#36201 - bump httpx: encode/httpx#3460 - bump ibm-db: ibmdb/python-ibmdb#971 - bump orjson: https://github.com/ijl/orjson/releases/tag/3.10.15 - bump pandas: https://github.com/pandas-dev/pandas/releases/tag/v2.2.3 >⚠️ `cryptography` is not compatible with python `3.9.0` and `3.9.1` to be able to update to the version supporting Python 3.13 we have to exclude those version, meaning the minimum version is now 3.9.2 included. --------- Signed-off-by: axel7083 <[email protected]> Co-authored-by: David Ankin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.