Skip to content

Commit 59ba1c5

Browse files
Separate tests into different components for easier debugging. (testcontainers#212)
* Restructure tests. * Update python version (closes testcontainers#188). * Separate tests using GitHub Action matrix. * Add information on contributing a new container. * Fix docker compose path. * Finish running test matrix even if one element fails. * Clean up print statements in tests. * Fix docker compose tests; remove mysql dependency.
1 parent 98398ff commit 59ba1c5

28 files changed

+523
-231
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,27 @@ on:
88
jobs:
99
build:
1010
strategy:
11+
fail-fast: false
1112
matrix:
12-
python-version: [3.6, 3.7, 3.8]
13+
python-version:
14+
- "3.7"
15+
- "3.8"
16+
- "3.9"
17+
- "3.10"
18+
test-component:
19+
- core
20+
- clickhouse.py
21+
- elasticsearch.py
22+
- google.py
23+
- kafka.py
24+
- localstack.py
25+
- mongodb.py
26+
- neo4j.py
27+
- nginx.py
28+
- rabbitmq.py
29+
- redis.py
30+
- selenium.py
31+
- webdriver.py
1332
runs-on: ubuntu-18.04
1433
steps:
1534
- uses: actions/checkout@v2
@@ -44,5 +63,5 @@ jobs:
4463
run: |
4564
flake8
4665
sphinx-build -nW docs docs/_build/html
47-
py.test -svx --cov-config .coveragerc --cov-report html:skip-covered --cov-report term:skip-covered --cov=testcontainers --tb=short tests/
66+
py.test -svx --cov-config .coveragerc --cov-report html:skip-covered --cov-report term:skip-covered --cov=testcontainers --tb=short tests/test_${{ matrix.test-component }}
4867
codecov

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PYTHON_VERSIONS = 3.6 3.7 3.8 3.9
1+
PYTHON_VERSIONS = 3.7 3.8 3.9 3.10
22
REQUIREMENTS = $(addprefix requirements/,${PYTHON_VERSIONS:=.txt})
33
TESTS = $(addprefix tests/,${PYTHON_VERSIONS})
44
IMAGES = $(addprefix image/,${PYTHON_VERSIONS})

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,12 @@ Adding requirements
7878
^^^^^^^^^^^^^^^^^^^
7979

8080
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.
81+
82+
Contributing a new container
83+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
85+
You can contribute a new container in three steps:
86+
87+
1. Create a new module at :code:`testcontainers/[my fancy container].py` that implements the new functionality.
88+
2. Create a new test module at :code:`tests/test_[my fancy container].py` that tests the new functionality.
89+
3. Add :code:`[my fancy container]` to the list of test components in the GitHub Action configuration at :code:`.github/workflows/main.yml`.

requirements/3.10.txt

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
#
2+
# This file is autogenerated by pip-compile with python 3.10
3+
# To update, run:
4+
#
5+
# pip-compile --output-file=requirements/3.10.txt requirements.in
6+
#
7+
-e file:.
8+
# via -r requirements.in
9+
alabaster==0.7.12
10+
# via sphinx
11+
asn1crypto==1.5.1
12+
# via scramp
13+
async-generator==1.10
14+
# via
15+
# trio
16+
# trio-websocket
17+
async-timeout==4.0.2
18+
# via redis
19+
attrs==21.4.0
20+
# via
21+
# jsonschema
22+
# outcome
23+
# pytest
24+
# trio
25+
babel==2.10.1
26+
# via sphinx
27+
bcrypt==3.2.2
28+
# via paramiko
29+
cachetools==5.0.0
30+
# via google-auth
31+
certifi==2021.10.8
32+
# via
33+
# requests
34+
# urllib3
35+
cffi==1.15.0
36+
# via
37+
# bcrypt
38+
# cryptography
39+
# pynacl
40+
charset-normalizer==2.0.12
41+
# via requests
42+
clickhouse-driver==0.2.3
43+
# via testcontainers
44+
codecov==2.1.12
45+
# via -r requirements.in
46+
coverage[toml]==6.3.2
47+
# via
48+
# codecov
49+
# pytest-cov
50+
cryptography==36.0.2
51+
# via
52+
# -r requirements.in
53+
# paramiko
54+
# pyopenssl
55+
# urllib3
56+
cx-oracle==8.3.0
57+
# via testcontainers
58+
deprecated==1.2.13
59+
# via redis
60+
deprecation==2.1.0
61+
# via testcontainers
62+
distro==1.7.0
63+
# via docker-compose
64+
docker[ssh]==5.0.3
65+
# via
66+
# docker-compose
67+
# testcontainers
68+
docker-compose==1.29.2
69+
# via testcontainers
70+
dockerpty==0.4.1
71+
# via docker-compose
72+
docopt==0.6.2
73+
# via docker-compose
74+
docutils==0.17.1
75+
# via sphinx
76+
entrypoints==0.3
77+
# via flake8
78+
flake8==3.7.9
79+
# via -r requirements.in
80+
google-api-core[grpc]==2.7.3
81+
# via google-cloud-pubsub
82+
google-auth==2.6.6
83+
# via google-api-core
84+
google-cloud-pubsub==1.7.1
85+
# via testcontainers
86+
googleapis-common-protos[grpc]==1.56.0
87+
# via
88+
# google-api-core
89+
# grpc-google-iam-v1
90+
# grpcio-status
91+
greenlet==1.1.2
92+
# via sqlalchemy
93+
grpc-google-iam-v1==0.12.4
94+
# via google-cloud-pubsub
95+
grpcio==1.46.0
96+
# via
97+
# google-api-core
98+
# googleapis-common-protos
99+
# grpc-google-iam-v1
100+
# grpcio-status
101+
grpcio-status==1.46.0
102+
# via google-api-core
103+
h11==0.13.0
104+
# via wsproto
105+
idna==3.3
106+
# via
107+
# requests
108+
# trio
109+
# urllib3
110+
imagesize==1.3.0
111+
# via sphinx
112+
iniconfig==1.1.1
113+
# via pytest
114+
jinja2==3.1.2
115+
# via sphinx
116+
jsonschema==3.2.0
117+
# via docker-compose
118+
kafka-python==2.0.2
119+
# via testcontainers
120+
markupsafe==2.1.1
121+
# via jinja2
122+
mccabe==0.6.1
123+
# via flake8
124+
neo4j==4.4.3
125+
# via testcontainers
126+
outcome==1.1.0
127+
# via trio
128+
packaging==21.3
129+
# via
130+
# deprecation
131+
# pytest
132+
# redis
133+
# sphinx
134+
paramiko==2.10.4
135+
# via docker
136+
pg8000==1.26.1
137+
# via -r requirements.in
138+
pika==1.2.1
139+
# via testcontainers
140+
pluggy==1.0.0
141+
# via pytest
142+
protobuf==3.20.1
143+
# via
144+
# google-api-core
145+
# googleapis-common-protos
146+
# grpcio-status
147+
psycopg2-binary==2.9.3
148+
# via testcontainers
149+
py==1.11.0
150+
# via pytest
151+
pyasn1==0.4.8
152+
# via
153+
# pyasn1-modules
154+
# rsa
155+
pyasn1-modules==0.2.8
156+
# via google-auth
157+
pycodestyle==2.5.0
158+
# via flake8
159+
pycparser==2.21
160+
# via cffi
161+
pyflakes==2.1.1
162+
# via flake8
163+
pygments==2.12.0
164+
# via sphinx
165+
pymongo==4.1.1
166+
# via testcontainers
167+
pymssql==2.2.5
168+
# via testcontainers
169+
pymysql==1.0.2
170+
# via testcontainers
171+
pynacl==1.5.0
172+
# via paramiko
173+
pyopenssl==22.0.0
174+
# via urllib3
175+
pyparsing==3.0.8
176+
# via packaging
177+
pyrsistent==0.18.1
178+
# via jsonschema
179+
pysocks==1.7.1
180+
# via urllib3
181+
pytest==7.1.2
182+
# via
183+
# -r requirements.in
184+
# pytest-cov
185+
pytest-cov==3.0.0
186+
# via -r requirements.in
187+
python-dotenv==0.20.0
188+
# via docker-compose
189+
pytz==2022.1
190+
# via
191+
# babel
192+
# clickhouse-driver
193+
# neo4j
194+
pytz-deprecation-shim==0.1.0.post0
195+
# via tzlocal
196+
pyyaml==5.4.1
197+
# via docker-compose
198+
redis==4.2.2
199+
# via testcontainers
200+
requests==2.27.1
201+
# via
202+
# codecov
203+
# docker
204+
# docker-compose
205+
# google-api-core
206+
# sphinx
207+
rsa==4.8
208+
# via google-auth
209+
scramp==1.4.1
210+
# via pg8000
211+
selenium==4.1.4
212+
# via testcontainers
213+
six==1.16.0
214+
# via
215+
# dockerpty
216+
# google-auth
217+
# grpcio
218+
# jsonschema
219+
# paramiko
220+
# websocket-client
221+
sniffio==1.2.0
222+
# via trio
223+
snowballstemmer==2.2.0
224+
# via sphinx
225+
sortedcontainers==2.4.0
226+
# via trio
227+
sphinx==4.5.0
228+
# via -r requirements.in
229+
sphinxcontrib-applehelp==1.0.2
230+
# via sphinx
231+
sphinxcontrib-devhelp==1.0.2
232+
# via sphinx
233+
sphinxcontrib-htmlhelp==2.0.0
234+
# via sphinx
235+
sphinxcontrib-jsmath==1.0.1
236+
# via sphinx
237+
sphinxcontrib-qthelp==1.0.3
238+
# via sphinx
239+
sphinxcontrib-serializinghtml==1.1.5
240+
# via sphinx
241+
sqlalchemy==1.4.36
242+
# via testcontainers
243+
texttable==1.6.4
244+
# via docker-compose
245+
tomli==2.0.1
246+
# via
247+
# coverage
248+
# pytest
249+
trio==0.20.0
250+
# via
251+
# selenium
252+
# trio-websocket
253+
trio-websocket==0.9.2
254+
# via selenium
255+
tzdata==2022.1
256+
# via pytz-deprecation-shim
257+
tzlocal==4.2
258+
# via clickhouse-driver
259+
urllib3[secure,socks]==1.26.9
260+
# via
261+
# requests
262+
# selenium
263+
websocket-client==0.59.0
264+
# via
265+
# docker
266+
# docker-compose
267+
wrapt==1.14.1
268+
# via
269+
# deprecated
270+
# testcontainers
271+
wsproto==1.1.0
272+
# via trio-websocket
273+
274+
# The following packages are considered to be unsafe in a requirements file:
275+
# setuptools

testcontainers/compose.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ def _get_service_info(self, service, port):
209209
port_cmd = self.docker_compose_command() + ["port", service, str(port)]
210210
output = subprocess.check_output(port_cmd, cwd=self.filepath).decode("utf-8")
211211
result = str(output).rstrip().split(":")
212-
if len(result) == 1:
213-
raise NoSuchPortExposed("Port {} was not exposed for service {}"
214-
.format(port, service))
212+
if len(result) != 2 or not all(result):
213+
raise NoSuchPortExposed(f"port {port} is not exposed for service {service}")
215214
return result
216215

217216
def _call_command(self, cmd, filepath=None):

tests/.env.test

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/Dockerfile

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/docker-compose-2.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/docker-compose-3.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/docker-compose-4.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)