Skip to content

Commit ae0e6c7

Browse files
authored
feat: --wait in the default setup command (#129)
1 parent 5c982af commit ae0e6c7

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def test_status_code(http_service):
9494
assert response.status_code == status
9595
```
9696
97+
> The default `docker_setup` command includes `--wait`, which respects either the
98+
> image `HEALTHCHECK` or the compose `healthcheck`. Generally, if those
99+
> are configured properly, `wait_until_responsive` should not be required.
100+
97101
By default, this plugin will try to open `docker-compose.yml` in your
98102
`tests` directory. If you need to use a custom location, override the
99103
`docker_compose_file` fixture inside your `conftest.py` file:
@@ -138,7 +142,7 @@ def docker_compose_project_name() -> str:
138142
# Stop the stack before starting a new one
139143
@pytest.fixture(scope="session")
140144
def docker_setup():
141-
return ["down -v", "up --build -d"]
145+
return ["down -v", "up --build --wait"]
142146
```
143147

144148

src/pytest_docker/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def docker_cleanup() -> Union[List[str], str]:
179179

180180

181181
def get_setup_command() -> Union[List[str], str]:
182-
return ["up --build -d"]
182+
return ["up --build --wait"]
183183

184184

185185
@pytest.fixture(scope=containers_scope)

tests/test_docker_services.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_docker_services() -> None:
4949
# Both should have been called.
5050
assert check_output.call_args_list == [
5151
mock.call(
52-
'docker compose -f "docker-compose.yml" -p "pytest123" up --build -d',
52+
'docker compose -f "docker-compose.yml" -p "pytest123" up --build --wait',
5353
stderr=subprocess.STDOUT,
5454
shell=True,
5555
),
@@ -100,7 +100,7 @@ def test_docker_services_unused_port() -> None:
100100
assert check_output.call_args_list == [
101101
mock.call(
102102
'docker compose -f "docker-compose.yml" -p "pytest123" '
103-
"up --build -d", # pylint: disable:=implicit-str-concat
103+
'up --build --wait', # pylint: disable:=implicit-str-concat
104104
shell=True,
105105
stderr=subprocess.STDOUT,
106106
),
@@ -147,7 +147,7 @@ def test_docker_services_failure() -> None:
147147
assert check_output.call_args_list == [
148148
mock.call(
149149
'docker compose -f "docker-compose.yml" -p "pytest123" '
150-
"up --build -d", # pylint: disable:=implicit-str-concat
150+
"up --build --wait", # pylint: disable:=implicit-str-concat
151151
shell=True,
152152
stderr=subprocess.STDOUT,
153153
)
@@ -188,7 +188,7 @@ def test_single_commands() -> None:
188188
"docker compose",
189189
"docker-compose.yml",
190190
docker_compose_project_name="pytest123",
191-
docker_setup="up --build -d",
191+
docker_setup="up --build --wait",
192192
docker_cleanup="down -v",
193193
) as services:
194194
assert isinstance(services, Services)
@@ -212,7 +212,7 @@ def test_single_commands() -> None:
212212
# Both should have been called.
213213
assert check_output.call_args_list == [
214214
mock.call(
215-
'docker compose -f "docker-compose.yml" -p "pytest123" up --build -d',
215+
'docker compose -f "docker-compose.yml" -p "pytest123" up --build --wait',
216216
stderr=subprocess.STDOUT,
217217
shell=True,
218218
),
@@ -242,7 +242,7 @@ def test_multiple_commands() -> None:
242242
"docker compose",
243243
"docker-compose.yml",
244244
docker_compose_project_name="pytest123",
245-
docker_setup=["ps", "up --build -d"],
245+
docker_setup=["ps", "up --build --wait"],
246246
docker_cleanup=["down -v", "ps"],
247247
) as services:
248248
assert isinstance(services, Services)
@@ -271,7 +271,7 @@ def test_multiple_commands() -> None:
271271
shell=True,
272272
),
273273
mock.call(
274-
'docker compose -f "docker-compose.yml" -p "pytest123" up --build -d',
274+
'docker compose -f "docker-compose.yml" -p "pytest123" up --build --wait',
275275
stderr=subprocess.STDOUT,
276276
shell=True,
277277
),

tests/test_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_docker_cleanup(docker_cleanup: List[str]) -> None:
2121

2222

2323
def test_docker_setup(docker_setup: List[str]) -> None:
24-
assert docker_setup == ["up --build -d"]
24+
assert docker_setup == ["up --build --wait"]
2525

2626

2727
def test_docker_compose_comand(docker_compose_command: str) -> None:

0 commit comments

Comments
 (0)