pytest-docker 2.1.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest-docker-2.1.0/src/pytest_docker.egg-info → pytest-docker-2.2.0}/PKG-INFO +18 -10
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/README.md +17 -9
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/setup.cfg +1 -1
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker/__init__.py +1 -2
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker/plugin.py +12 -6
- {pytest-docker-2.1.0 → pytest-docker-2.2.0/src/pytest_docker.egg-info}/PKG-INFO +18 -10
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/tests/test_docker_services.py +118 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/tests/test_fixtures.py +5 -3
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/LICENSE.txt +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/pyproject.toml +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/setup.py +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker.egg-info/SOURCES.txt +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker.egg-info/dependency_links.txt +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker.egg-info/entry_points.txt +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker.egg-info/requires.txt +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/src/pytest_docker.egg-info/top_level.txt +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/tests/test_docker_ip.py +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/tests/test_dockercomposeexecutor.py +0 -0
- {pytest-docker-2.1.0 → pytest-docker-2.2.0}/tests/test_integration.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pytest-docker
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Simple pytest fixtures for Docker and Docker Compose based tests
|
|
5
5
|
Home-page: https://github.com/avast/pytest-docker
|
|
6
6
|
Author: Max K., Andre Caron
|
|
@@ -33,13 +33,14 @@ Requires-Dist: pytest-pycodestyle<3.0,>=2.0.0; extra == "tests"
|
|
|
33
33
|
|
|
34
34
|
Docker-based integration tests
|
|
35
35
|
=====
|
|
36
|
+
|
|
36
37
|
[](https://pypi.org/project/pytest-docker/)
|
|
37
38
|
[](https://github.com/avast/pytest-docker/actions/workflows/tests.yaml)
|
|
38
39
|
[](https://pypi.org/project/pytest-docker/)
|
|
39
40
|
[](https://github.com/psf/black)
|
|
40
41
|
|
|
41
|
-
|
|
42
42
|
# Description
|
|
43
|
+
|
|
43
44
|
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
|
|
44
45
|
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
|
|
45
46
|
Specify all necessary containers in a `docker-compose.yml` file and and
|
|
@@ -51,6 +52,7 @@ This package is tested with Python versions `3.6`, `3.7`, `3.8` and
|
|
|
51
52
|
`pytest-docker` was originally created by André Caron.
|
|
52
53
|
|
|
53
54
|
# Installation
|
|
55
|
+
|
|
54
56
|
Install `pytest-docker` with `pip` or add it to your test requirements.
|
|
55
57
|
|
|
56
58
|
By default, it uses the `docker compose` command, so it relies on the Compose plugin for Docker (also called Docker Compose V2).
|
|
@@ -67,6 +69,7 @@ def docker_compose_command() -> str:
|
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
If you want to use the pip-distributed version of `docker-compose` command, you can install it using
|
|
72
|
+
|
|
70
73
|
```
|
|
71
74
|
pip install pytest-docker[docker-compose-v1]
|
|
72
75
|
```
|
|
@@ -74,6 +77,7 @@ pip install pytest-docker[docker-compose-v1]
|
|
|
74
77
|
Another option could be usage of [`compose-switch`](https://github.com/docker/compose-switch).
|
|
75
78
|
|
|
76
79
|
# Usage
|
|
80
|
+
|
|
77
81
|
Here is an example of a test that depends on a HTTP service.
|
|
78
82
|
|
|
79
83
|
With a `docker-compose.yml` file like this (using the
|
|
@@ -150,7 +154,7 @@ pytest --container-scope <scope> <test_directory>
|
|
|
150
154
|
```
|
|
151
155
|
|
|
152
156
|
For available scopes and descriptions
|
|
153
|
-
see https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes
|
|
157
|
+
see <https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes>
|
|
154
158
|
|
|
155
159
|
### `docker_ip`
|
|
156
160
|
|
|
@@ -179,29 +183,33 @@ Docker Compose V1, change this fixture to return `docker-compose`.
|
|
|
179
183
|
|
|
180
184
|
### `docker_setup`
|
|
181
185
|
|
|
182
|
-
Get the docker_compose
|
|
186
|
+
Get the list of docker_compose commands to be executed for test spawn actions.
|
|
183
187
|
Override this fixture in your tests if you need to change spawn actions.
|
|
184
188
|
Returning anything that would evaluate to False will skip this command.
|
|
185
189
|
|
|
186
190
|
### `docker_cleanup`
|
|
187
191
|
|
|
188
|
-
Get the docker_compose
|
|
192
|
+
Get the list of docker_compose commands to be executed for test clean-up actions.
|
|
189
193
|
Override this fixture in your tests if you need to change clean-up actions.
|
|
190
194
|
Returning anything that would evaluate to False will skip this command.
|
|
191
195
|
|
|
192
|
-
|
|
193
196
|
# Development
|
|
197
|
+
|
|
194
198
|
Use of a virtual environment is recommended. See the
|
|
195
199
|
[venv](https://docs.python.org/3/library/venv.html) package for more
|
|
196
200
|
information.
|
|
197
201
|
|
|
198
202
|
First, install `pytest-docker` and its test dependencies:
|
|
199
203
|
|
|
200
|
-
|
|
204
|
+
```bash
|
|
205
|
+
pip install -e ".[tests]"
|
|
206
|
+
```
|
|
201
207
|
|
|
202
208
|
Run tests with
|
|
203
209
|
|
|
204
|
-
|
|
210
|
+
```bash
|
|
211
|
+
pytest -c setup.cfg
|
|
212
|
+
```
|
|
205
213
|
|
|
206
214
|
to make sure that the correct configuration is used. This is also how tests are
|
|
207
215
|
run in CI.
|
|
@@ -210,9 +218,9 @@ Use [black](https://pypi.org/project/black/) with default settings for
|
|
|
210
218
|
formatting. You can also use `pylint` with `setup.cfg` as the configuration
|
|
211
219
|
file.
|
|
212
220
|
|
|
213
|
-
|
|
214
221
|
# Contributing
|
|
215
|
-
|
|
222
|
+
|
|
223
|
+
This `pytest` plug-in and its source code are made available to you under a MIT
|
|
216
224
|
license. It is safe to use in commercial and closed-source applications. Read
|
|
217
225
|
the license for details!
|
|
218
226
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Docker-based integration tests
|
|
2
2
|
=====
|
|
3
|
+
|
|
3
4
|
[](https://pypi.org/project/pytest-docker/)
|
|
4
5
|
[](https://github.com/avast/pytest-docker/actions/workflows/tests.yaml)
|
|
5
6
|
[](https://pypi.org/project/pytest-docker/)
|
|
6
7
|
[](https://github.com/psf/black)
|
|
7
8
|
|
|
8
|
-
|
|
9
9
|
# Description
|
|
10
|
+
|
|
10
11
|
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
|
|
11
12
|
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
|
|
12
13
|
Specify all necessary containers in a `docker-compose.yml` file and and
|
|
@@ -18,6 +19,7 @@ This package is tested with Python versions `3.6`, `3.7`, `3.8` and
|
|
|
18
19
|
`pytest-docker` was originally created by André Caron.
|
|
19
20
|
|
|
20
21
|
# Installation
|
|
22
|
+
|
|
21
23
|
Install `pytest-docker` with `pip` or add it to your test requirements.
|
|
22
24
|
|
|
23
25
|
By default, it uses the `docker compose` command, so it relies on the Compose plugin for Docker (also called Docker Compose V2).
|
|
@@ -34,6 +36,7 @@ def docker_compose_command() -> str:
|
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
If you want to use the pip-distributed version of `docker-compose` command, you can install it using
|
|
39
|
+
|
|
37
40
|
```
|
|
38
41
|
pip install pytest-docker[docker-compose-v1]
|
|
39
42
|
```
|
|
@@ -41,6 +44,7 @@ pip install pytest-docker[docker-compose-v1]
|
|
|
41
44
|
Another option could be usage of [`compose-switch`](https://github.com/docker/compose-switch).
|
|
42
45
|
|
|
43
46
|
# Usage
|
|
47
|
+
|
|
44
48
|
Here is an example of a test that depends on a HTTP service.
|
|
45
49
|
|
|
46
50
|
With a `docker-compose.yml` file like this (using the
|
|
@@ -117,7 +121,7 @@ pytest --container-scope <scope> <test_directory>
|
|
|
117
121
|
```
|
|
118
122
|
|
|
119
123
|
For available scopes and descriptions
|
|
120
|
-
see https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes
|
|
124
|
+
see <https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes>
|
|
121
125
|
|
|
122
126
|
### `docker_ip`
|
|
123
127
|
|
|
@@ -146,29 +150,33 @@ Docker Compose V1, change this fixture to return `docker-compose`.
|
|
|
146
150
|
|
|
147
151
|
### `docker_setup`
|
|
148
152
|
|
|
149
|
-
Get the docker_compose
|
|
153
|
+
Get the list of docker_compose commands to be executed for test spawn actions.
|
|
150
154
|
Override this fixture in your tests if you need to change spawn actions.
|
|
151
155
|
Returning anything that would evaluate to False will skip this command.
|
|
152
156
|
|
|
153
157
|
### `docker_cleanup`
|
|
154
158
|
|
|
155
|
-
Get the docker_compose
|
|
159
|
+
Get the list of docker_compose commands to be executed for test clean-up actions.
|
|
156
160
|
Override this fixture in your tests if you need to change clean-up actions.
|
|
157
161
|
Returning anything that would evaluate to False will skip this command.
|
|
158
162
|
|
|
159
|
-
|
|
160
163
|
# Development
|
|
164
|
+
|
|
161
165
|
Use of a virtual environment is recommended. See the
|
|
162
166
|
[venv](https://docs.python.org/3/library/venv.html) package for more
|
|
163
167
|
information.
|
|
164
168
|
|
|
165
169
|
First, install `pytest-docker` and its test dependencies:
|
|
166
170
|
|
|
167
|
-
|
|
171
|
+
```bash
|
|
172
|
+
pip install -e ".[tests]"
|
|
173
|
+
```
|
|
168
174
|
|
|
169
175
|
Run tests with
|
|
170
176
|
|
|
171
|
-
|
|
177
|
+
```bash
|
|
178
|
+
pytest -c setup.cfg
|
|
179
|
+
```
|
|
172
180
|
|
|
173
181
|
to make sure that the correct configuration is used. This is also how tests are
|
|
174
182
|
run in CI.
|
|
@@ -177,9 +185,9 @@ Use [black](https://pypi.org/project/black/) with default settings for
|
|
|
177
185
|
formatting. You can also use `pylint` with `setup.cfg` as the configuration
|
|
178
186
|
file.
|
|
179
187
|
|
|
180
|
-
|
|
181
188
|
# Contributing
|
|
182
|
-
|
|
189
|
+
|
|
190
|
+
This `pytest` plug-in and its source code are made available to you under a MIT
|
|
183
191
|
license. It is safe to use in commercial and closed-source applications. Read
|
|
184
192
|
the license for details!
|
|
185
193
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
from .plugin import (
|
|
3
|
-
docker_cleanup,
|
|
4
3
|
docker_compose_command,
|
|
5
4
|
docker_compose_file,
|
|
6
5
|
docker_compose_project_name,
|
|
@@ -11,7 +10,7 @@ from .plugin import (
|
|
|
11
10
|
)
|
|
12
11
|
|
|
13
12
|
__all__ = [
|
|
14
|
-
"
|
|
13
|
+
"docker_compose_command",
|
|
15
14
|
"docker_compose_file",
|
|
16
15
|
"docker_compose_project_name",
|
|
17
16
|
"docker_ip",
|
|
@@ -162,8 +162,7 @@ def docker_compose_project_name():
|
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
def get_cleanup_command():
|
|
165
|
-
|
|
166
|
-
return "down -v"
|
|
165
|
+
return ["down -v"]
|
|
167
166
|
|
|
168
167
|
|
|
169
168
|
@pytest.fixture(scope=containers_scope)
|
|
@@ -176,8 +175,7 @@ def docker_cleanup():
|
|
|
176
175
|
|
|
177
176
|
|
|
178
177
|
def get_setup_command():
|
|
179
|
-
|
|
180
|
-
return "up --build -d"
|
|
178
|
+
return ["up --build -d"]
|
|
181
179
|
|
|
182
180
|
|
|
183
181
|
@pytest.fixture(scope=containers_scope)
|
|
@@ -203,7 +201,11 @@ def get_docker_services(
|
|
|
203
201
|
|
|
204
202
|
# setup containers.
|
|
205
203
|
if docker_setup:
|
|
206
|
-
|
|
204
|
+
# Maintain backwards compatibility with the string format.
|
|
205
|
+
if isinstance(docker_setup, str):
|
|
206
|
+
docker_setup = [docker_setup]
|
|
207
|
+
for command in docker_setup:
|
|
208
|
+
docker_compose.execute(command)
|
|
207
209
|
|
|
208
210
|
try:
|
|
209
211
|
# Let test(s) run.
|
|
@@ -211,7 +213,11 @@ def get_docker_services(
|
|
|
211
213
|
finally:
|
|
212
214
|
# Clean up.
|
|
213
215
|
if docker_cleanup:
|
|
214
|
-
|
|
216
|
+
# Maintain backwards compatibility with the string format.
|
|
217
|
+
if isinstance(docker_cleanup, str):
|
|
218
|
+
docker_cleanup = [docker_cleanup]
|
|
219
|
+
for command in docker_cleanup:
|
|
220
|
+
docker_compose.execute(command)
|
|
215
221
|
|
|
216
222
|
|
|
217
223
|
@pytest.fixture(scope=containers_scope)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pytest-docker
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Simple pytest fixtures for Docker and Docker Compose based tests
|
|
5
5
|
Home-page: https://github.com/avast/pytest-docker
|
|
6
6
|
Author: Max K., Andre Caron
|
|
@@ -33,13 +33,14 @@ Requires-Dist: pytest-pycodestyle<3.0,>=2.0.0; extra == "tests"
|
|
|
33
33
|
|
|
34
34
|
Docker-based integration tests
|
|
35
35
|
=====
|
|
36
|
+
|
|
36
37
|
[](https://pypi.org/project/pytest-docker/)
|
|
37
38
|
[](https://github.com/avast/pytest-docker/actions/workflows/tests.yaml)
|
|
38
39
|
[](https://pypi.org/project/pytest-docker/)
|
|
39
40
|
[](https://github.com/psf/black)
|
|
40
41
|
|
|
41
|
-
|
|
42
42
|
# Description
|
|
43
|
+
|
|
43
44
|
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
|
|
44
45
|
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
|
|
45
46
|
Specify all necessary containers in a `docker-compose.yml` file and and
|
|
@@ -51,6 +52,7 @@ This package is tested with Python versions `3.6`, `3.7`, `3.8` and
|
|
|
51
52
|
`pytest-docker` was originally created by André Caron.
|
|
52
53
|
|
|
53
54
|
# Installation
|
|
55
|
+
|
|
54
56
|
Install `pytest-docker` with `pip` or add it to your test requirements.
|
|
55
57
|
|
|
56
58
|
By default, it uses the `docker compose` command, so it relies on the Compose plugin for Docker (also called Docker Compose V2).
|
|
@@ -67,6 +69,7 @@ def docker_compose_command() -> str:
|
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
If you want to use the pip-distributed version of `docker-compose` command, you can install it using
|
|
72
|
+
|
|
70
73
|
```
|
|
71
74
|
pip install pytest-docker[docker-compose-v1]
|
|
72
75
|
```
|
|
@@ -74,6 +77,7 @@ pip install pytest-docker[docker-compose-v1]
|
|
|
74
77
|
Another option could be usage of [`compose-switch`](https://github.com/docker/compose-switch).
|
|
75
78
|
|
|
76
79
|
# Usage
|
|
80
|
+
|
|
77
81
|
Here is an example of a test that depends on a HTTP service.
|
|
78
82
|
|
|
79
83
|
With a `docker-compose.yml` file like this (using the
|
|
@@ -150,7 +154,7 @@ pytest --container-scope <scope> <test_directory>
|
|
|
150
154
|
```
|
|
151
155
|
|
|
152
156
|
For available scopes and descriptions
|
|
153
|
-
see https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes
|
|
157
|
+
see <https://docs.pytest.org/en/6.2.x/fixture.html#fixture-scopes>
|
|
154
158
|
|
|
155
159
|
### `docker_ip`
|
|
156
160
|
|
|
@@ -179,29 +183,33 @@ Docker Compose V1, change this fixture to return `docker-compose`.
|
|
|
179
183
|
|
|
180
184
|
### `docker_setup`
|
|
181
185
|
|
|
182
|
-
Get the docker_compose
|
|
186
|
+
Get the list of docker_compose commands to be executed for test spawn actions.
|
|
183
187
|
Override this fixture in your tests if you need to change spawn actions.
|
|
184
188
|
Returning anything that would evaluate to False will skip this command.
|
|
185
189
|
|
|
186
190
|
### `docker_cleanup`
|
|
187
191
|
|
|
188
|
-
Get the docker_compose
|
|
192
|
+
Get the list of docker_compose commands to be executed for test clean-up actions.
|
|
189
193
|
Override this fixture in your tests if you need to change clean-up actions.
|
|
190
194
|
Returning anything that would evaluate to False will skip this command.
|
|
191
195
|
|
|
192
|
-
|
|
193
196
|
# Development
|
|
197
|
+
|
|
194
198
|
Use of a virtual environment is recommended. See the
|
|
195
199
|
[venv](https://docs.python.org/3/library/venv.html) package for more
|
|
196
200
|
information.
|
|
197
201
|
|
|
198
202
|
First, install `pytest-docker` and its test dependencies:
|
|
199
203
|
|
|
200
|
-
|
|
204
|
+
```bash
|
|
205
|
+
pip install -e ".[tests]"
|
|
206
|
+
```
|
|
201
207
|
|
|
202
208
|
Run tests with
|
|
203
209
|
|
|
204
|
-
|
|
210
|
+
```bash
|
|
211
|
+
pytest -c setup.cfg
|
|
212
|
+
```
|
|
205
213
|
|
|
206
214
|
to make sure that the correct configuration is used. This is also how tests are
|
|
207
215
|
run in CI.
|
|
@@ -210,9 +218,9 @@ Use [black](https://pypi.org/project/black/) with default settings for
|
|
|
210
218
|
formatting. You can also use `pylint` with `setup.cfg` as the configuration
|
|
211
219
|
file.
|
|
212
220
|
|
|
213
|
-
|
|
214
221
|
# Contributing
|
|
215
|
-
|
|
222
|
+
|
|
223
|
+
This `pytest` plug-in and its source code are made available to you under a MIT
|
|
216
224
|
license. It is safe to use in commercial and closed-source applications. Read
|
|
217
225
|
the license for details!
|
|
218
226
|
|
|
@@ -174,3 +174,121 @@ def test_wait_until_responsive_timeout():
|
|
|
174
174
|
)
|
|
175
175
|
assert sleep.call_args_list == [mock.call(1.0), mock.call(1.0), mock.call(1.0)]
|
|
176
176
|
assert str(exc.value) == ("Timeout reached while waiting on service!")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_single_commands():
|
|
180
|
+
"""Ensures backwards compatibility with single command strings for setup and cleanup."""
|
|
181
|
+
|
|
182
|
+
with mock.patch("subprocess.check_output") as check_output:
|
|
183
|
+
check_output.returncode = 0
|
|
184
|
+
|
|
185
|
+
assert check_output.call_count == 0
|
|
186
|
+
|
|
187
|
+
# The fixture is a context-manager.
|
|
188
|
+
with get_docker_services(
|
|
189
|
+
"docker compose",
|
|
190
|
+
"docker-compose.yml",
|
|
191
|
+
docker_compose_project_name="pytest123",
|
|
192
|
+
docker_setup="up --build -d",
|
|
193
|
+
docker_cleanup="down -v",
|
|
194
|
+
) as services:
|
|
195
|
+
assert isinstance(services, Services)
|
|
196
|
+
|
|
197
|
+
assert check_output.call_count == 1
|
|
198
|
+
|
|
199
|
+
# Can request port for services.
|
|
200
|
+
port = services.port_for("hello", 80)
|
|
201
|
+
assert port == 1
|
|
202
|
+
|
|
203
|
+
assert check_output.call_count == 2
|
|
204
|
+
|
|
205
|
+
# 2nd request for same service should hit the cache.
|
|
206
|
+
port = services.port_for("hello", 80)
|
|
207
|
+
assert port == 1
|
|
208
|
+
|
|
209
|
+
assert check_output.call_count == 2
|
|
210
|
+
|
|
211
|
+
assert check_output.call_count == 3
|
|
212
|
+
|
|
213
|
+
# Both should have been called.
|
|
214
|
+
assert check_output.call_args_list == [
|
|
215
|
+
mock.call(
|
|
216
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" up --build -d',
|
|
217
|
+
stderr=subprocess.STDOUT,
|
|
218
|
+
shell=True,
|
|
219
|
+
),
|
|
220
|
+
mock.call(
|
|
221
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" port hello 80',
|
|
222
|
+
stderr=subprocess.STDOUT,
|
|
223
|
+
shell=True,
|
|
224
|
+
),
|
|
225
|
+
mock.call(
|
|
226
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" down -v',
|
|
227
|
+
stderr=subprocess.STDOUT,
|
|
228
|
+
shell=True,
|
|
229
|
+
),
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def test_multiple_commands():
|
|
234
|
+
"""Multiple startup and cleanup commands should be executed."""
|
|
235
|
+
|
|
236
|
+
with mock.patch("subprocess.check_output") as check_output:
|
|
237
|
+
check_output.returncode = 0
|
|
238
|
+
|
|
239
|
+
assert check_output.call_count == 0
|
|
240
|
+
|
|
241
|
+
# The fixture is a context-manager.
|
|
242
|
+
with get_docker_services(
|
|
243
|
+
"docker compose",
|
|
244
|
+
"docker-compose.yml",
|
|
245
|
+
docker_compose_project_name="pytest123",
|
|
246
|
+
docker_setup=["ps", "up --build -d"],
|
|
247
|
+
docker_cleanup=["down -v", "ps"],
|
|
248
|
+
) as services:
|
|
249
|
+
assert isinstance(services, Services)
|
|
250
|
+
|
|
251
|
+
assert check_output.call_count == 2
|
|
252
|
+
|
|
253
|
+
# Can request port for services.
|
|
254
|
+
port = services.port_for("hello", 80)
|
|
255
|
+
assert port == 1
|
|
256
|
+
|
|
257
|
+
assert check_output.call_count == 3
|
|
258
|
+
|
|
259
|
+
# 2nd request for same service should hit the cache.
|
|
260
|
+
port = services.port_for("hello", 80)
|
|
261
|
+
assert port == 1
|
|
262
|
+
|
|
263
|
+
assert check_output.call_count == 3
|
|
264
|
+
|
|
265
|
+
assert check_output.call_count == 5
|
|
266
|
+
|
|
267
|
+
# Both should have been called.
|
|
268
|
+
assert check_output.call_args_list == [
|
|
269
|
+
mock.call(
|
|
270
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" ps',
|
|
271
|
+
stderr=subprocess.STDOUT,
|
|
272
|
+
shell=True,
|
|
273
|
+
),
|
|
274
|
+
mock.call(
|
|
275
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" up --build -d',
|
|
276
|
+
stderr=subprocess.STDOUT,
|
|
277
|
+
shell=True,
|
|
278
|
+
),
|
|
279
|
+
mock.call(
|
|
280
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" port hello 80',
|
|
281
|
+
stderr=subprocess.STDOUT,
|
|
282
|
+
shell=True,
|
|
283
|
+
),
|
|
284
|
+
mock.call(
|
|
285
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" down -v',
|
|
286
|
+
stderr=subprocess.STDOUT,
|
|
287
|
+
shell=True,
|
|
288
|
+
),
|
|
289
|
+
mock.call(
|
|
290
|
+
'docker compose -f "docker-compose.yml" -p "pytest123" ps',
|
|
291
|
+
stderr=subprocess.STDOUT,
|
|
292
|
+
shell=True,
|
|
293
|
+
),
|
|
294
|
+
]
|
|
@@ -13,14 +13,16 @@ def test_docker_compose_project(docker_compose_project_name):
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def test_docker_cleanup(docker_cleanup):
|
|
16
|
-
assert docker_cleanup == "down -v"
|
|
16
|
+
assert docker_cleanup == ["down -v"]
|
|
17
|
+
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
def test_docker_setup(docker_setup):
|
|
20
|
-
assert docker_setup == "up --build -d"
|
|
21
|
+
assert docker_setup == ["up --build -d"]
|
|
22
|
+
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
def
|
|
25
|
+
def test_docker_compose_command(docker_compose_command):
|
|
24
26
|
assert docker_compose_command == "docker compose"
|
|
25
27
|
|
|
26
28
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|