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
You have implemented a new container and would like to contribute it? Great! Here are the necessary steps:
1
+
You have implemented a new container and would like to contribute it? Great! Here are the necessary steps.
2
2
3
-
-[ ] You have added the new container as a module in the `testcontainers` directory (such as `testcontainers/my_fancy_container.py`).
4
-
-[ ] You have added any new python dependencies in the `extras_require` section of `setup.py`.
5
-
-[ ] You have added the `extra_requires` key to `requirements.in`.
6
-
-[ ] You have updated all python requirements by running `make requirements` from the root directory.
7
-
-[ ] You have added tests for the new container in the `tests` directory, e.g. `tests/test_my_fancy_container.py`.
8
-
-[ ] You have added the name of the container (such as `my_fancy_container`) to the `test-components` matrix in `.github/workflows/main.yml` to ensure the tests are run.
9
-
-[ ] You have rebased your development branch on `master` (or merged `master` into your development branch).
3
+
-[ ] Create a new feature directory and populate it with the package structure [described in the documentation](https://testcontainers-python.readthedocs.io/en/latest/#package-structure). Copying one of the existing features is likely the best way to get started.
4
+
-[ ] Implement the new feature (typically in `__init__.py`) and corresponding tests.
5
+
-[ ] Add a line `-e file:[feature name]` to `requirements.in` and run `make requirements`. This command will find any new requirements and generate lock files to ensure reproducible builds (see the [pip-tools documentation](https://pip-tools.readthedocs.io/en/latest/) for details). Then run `pip install -r requirements/[your python version].txt` to install the new requirements.
6
+
-[ ] Update the feature `README.rst` and add it to the table of contents (`toctree` directive) in the top-level `README.rst`.
7
+
-[ ] Add a line `[feature name]` to the list of components in the GitHub Action workflow in `.github/workflows/main.yml` to run tests, build, and publish your package when pushed to the `master` branch.
8
+
-[ ] Rebase your development branch on `master` (or merge `master` into your development branch).
@@ -56,39 +55,64 @@ The snippet above will spin up a postgres database in a container. The :code:`ge
56
55
Installation
57
56
------------
58
57
59
-
The suite of testcontainers packages is available on `PyPI <https://pypi.org/project/testcontainers/>`_, and individual packages can be installed using :code:`pip`. We recommend installing the package you need by running :code:`pip install testcontainers-<feature>`, e.g., :code:`pip install testcontainers-mysql`.
58
+
The suite of testcontainers packages is available on `PyPI <https://pypi.org/project/testcontainers/>`_, and individual packages can be installed using :code:`pip`. We recommend installing the package you need by running :code:`pip install testcontainers-<feature>`, e.g., :code:`pip install testcontainers-postgres`.
60
59
61
-
For backwards compatibility, packages can also be installed by specifying `extras <https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies>`__, e.g., :code:`pip install testcontainers[mysql]`.
60
+
.. note::
62
61
62
+
For backwards compatibility, packages can also be installed by specifying `extras <https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies>`__, e.g., :code:`pip install testcontainers[postgres]`.
63
63
64
-
Usage within Docker (e.g., in a CI)
65
-
-----------------------------------
66
64
67
-
When trying to launch a testcontainer from within a Docker container two things have to be provided:
65
+
Docker in Docker (DinD)
66
+
-----------------------
67
+
68
+
When trying to launch a testcontainer from within a Docker container, e.g., in continuous integration testing, two things have to be provided:
68
69
69
70
1. The container has to provide a docker client installation. Either use an image that has docker pre-installed (e.g. the `official docker images <https://hub.docker.com/_/docker>`_) or install the client from within the `Dockerfile` specification.
70
71
2. The container has to have access to the docker daemon which can be achieved by mounting `/var/run/docker.sock` or setting the `DOCKER_HOST` environment variable as part of your `docker run` command.
71
72
72
-
Setting up a development environment
73
-
------------------------------------
73
+
Development and Contributing
74
+
----------------------------
74
75
75
-
We recommend you use a `virtual environment <https://virtualenv.pypa.io/en/stable/>`_ for development. Note that a python version :code:`>=3.7` is required. After setting up your virtual environment, you can install all dependencies and test the installation by running the following snippet.
76
+
We recommend you use a `virtual environment <https://virtualenv.pypa.io/en/stable/>`_ for development (:code:`python>=3.7` is required). After setting up your virtual environment, you can install all dependencies and test the installation by running the following snippet.
We use :code:`pip-tools` to resolve and manage dependencies. If you need to add a dependency to testcontainers or one of the extras, modify the :code:`setup.py` as well as the :code:`requirements.in` accordingly and then run :code:`pip install pip-tools` followed by :code:`make requirements` to update the requirements files.
83
+
Package Structure
84
+
^^^^^^^^^^^^^^^^^
86
85
87
-
Contributing a new container
88
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
+
Testcontainers is a collection of `implicit namespace packages <https://peps.python.org/pep-0420/>`__ to decouple the development of different extensions, e.g., :code:`testcontainers-mysql` and :code:`testcontainers-postgres` for MySQL and PostgreSQL database containers, respectively. The folder structure is as follows.
89
87
90
-
You can contribute a new container in three steps:
88
+
.. code-block:: bash
91
89
92
-
1. Create a new module at :code:`testcontainers/[my fancy container].py` that implements the new functionality.
93
-
2. Create a new test module at :code:`tests/test_[my fancy container].py` that tests the new functionality.
94
-
3. Add :code:`[my fancy container]` to the list of test components in the GitHub Action configuration at :code:`.github/workflows/main.yml`.
90
+
# One folder per feature.
91
+
[feature name]
92
+
# Folder without __init__.py for implicit namespace packages.
93
+
testcontainers
94
+
# Implementation as namespace package with __init__.py.
95
+
[feature name]
96
+
__init__.py
97
+
# Other files for this
98
+
...
99
+
# Tests for the feature.
100
+
tests
101
+
test_[feature_name].py
102
+
...
103
+
# README for this feature.
104
+
README.rst
105
+
# Setup script for this feature.
106
+
setup.py
107
+
108
+
Contributing a New Feature
109
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
110
+
111
+
You want to contribute a new feature or container? Great! You can do that in six steps.
112
+
113
+
1. Create a new feature directory and populate it with the [package structure]_ as described above. Copying one of the existing features is likely the best way to get started.
114
+
2. Implement the new feature (typically in :code:`__init__.py`) and corresponding tests.
115
+
3. Add a line :code:`-e file:[feature name]` to :code:`requirements.in` and run :code:`make requirements`. This command will find any new requirements and generate lock files to ensure reproducible builds (see the `pip-tools <https://pip-tools.readthedocs.io/en/latest/>`__ documentation for details). Then run :code:`pip install -r requirements/[your python version].txt` to install the new requirements.
116
+
4. Update the feature :code:`README.rst` and add it to the table of contents (:code:`toctree` directive) in the top-level :code:`README.rst`.
117
+
5. Add a line :code:`[feature name]` to the list of components in the GitHub Action workflow in :code:`.github/workflows/main.yml` to run tests, build, and publish your package when pushed to the :code:`master` branch.
118
+
6. Rebase your development branch on :code:`master` (or merge :code:`master` into your development branch).
0 commit comments