Skip to content

Commit 052e08b

Browse files
authored
feat!: V2 as default (#94)
* feat!: V2 as default * Python 3.6 removed from the test matrix * chore: Python 3.10 and 3.11 added to test matrix
1 parent 519b155 commit 052e08b

File tree

8 files changed

+49
-47
lines changed

8 files changed

+49
-47
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.6", "3.7", "3.8", "3.9"]
10+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1111
pytest-version: [4, 5, 6, 7]
1212

1313
steps:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Version 2.0.0
4+
Breaking changes:
5+
- Default command changed from `docker-compose` to `docker compose`, so the V2 is the default one.
6+
37
## Version 1.0.1
48
Chore:
59
- Set dependency on `attrs` to be the same as in `pytest`

README.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Docker-based integration tests
88

99
# Description
1010
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
11-
tests with Docker and [docker-compose](https://docs.docker.com/compose/).
11+
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
1212
Specify all necessary containers in a `docker-compose.yml` file and and
1313
`pytest-docker` will spin them up for the duration of your tests.
1414

@@ -18,30 +18,27 @@ This package is tested with Python versions `3.6`, `3.7`, `3.8` and
1818
`pytest-docker` was originally created by André Caron.
1919

2020
# Installation
21-
Install `pytest-docker` with `pip` or add it to your test requirements. It is
22-
recommended to install `docker-compose` python package directly in your
23-
environment to ensure that it is available during tests. This will prevent
24-
potential dependency conflicts that can occur when the system wide
25-
`docker-compose` is used in tests.
21+
Install `pytest-docker` with `pip` or add it to your test requirements.
2622

27-
The default behavior is not to install `docker-compose` with `pytest-docker`. If you
28-
want to, you install `pytest-docker` with the `docker-compose-v1`
29-
extra. You can use the following command:
23+
By default, it uses the `docker compose` command, so it relies on the Compose plugin for Docker (also called Docker Compose V2).
3024

25+
## Docker Compose V1 compatibility
26+
27+
If you want to use the old `docker-compose` command (deprecated since July 2023, not receiving updates since 2021)
28+
then you can do it using the [`docker-compose-command`](#docker_compose_command) fixture:
29+
30+
```python
31+
@pytest.fixture(scope="session")
32+
def docker_compose_command() -> str:
33+
return "docker-compose"
34+
```
35+
36+
If you want to use the pip-distributed version of `docker-compose` command, you can install it using
3137
```
3238
pip install pytest-docker[docker-compose-v1]
3339
```
3440

35-
## Docker Compose v2 compatiblity
36-
37-
`pytest-docker` will work with Docker Compose v2 out of the box if
38-
[`compose-switch`](https://github.com/docker/compose-switch)
39-
is installed.
40-
41-
If you want to use the real Docker Compose v2, it has to be installed
42-
system wide ([more information](https://github.com/docker/compose#linux))
43-
and you have to modify the [`docker-compose-command`](#docker_compose_command)
44-
fixture (this behavior might change in the future versions).
41+
Another option could be usage of [`compose-switch`](https://github.com/docker/compose-switch).
4542

4643
# Usage
4744
Here is an example of a test that depends on a HTTP service.
@@ -135,8 +132,8 @@ After test are finished, shutdown all services (`docker-compose down`).
135132
### `docker_compose_command`
136133

137134
Docker Compose command to use to execute Dockers. Default is to use
138-
Docker Compose v1 (command is `docker-compose`). If you want to use
139-
Docker Compose v2, change this fixture to return `docker compose`.
135+
Docker Compose V2 (command is `docker compose`). If you want to use
136+
Docker Compose V1, change this fixture to return `docker-compose`.
140137

141138
### `docker_setup`
142139

setup.cfg

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
name = pytest-docker
3-
version = 1.0.1
4-
description = Simple pytest fixtures for Docker and docker-compose based tests
3+
version = 2.0.0
4+
description = Simple pytest fixtures for Docker and Docker Compose based tests
55
long_description = file: README.md
66
long_description_content_type = text/markdown
77
keywords = docker,docker-compose,pytest
@@ -13,10 +13,11 @@ author_email = [email protected]
1313
license = MIT
1414
classifiers =
1515
Programming Language :: Python :: 3
16-
Programming Language :: Python :: 3.6
1716
Programming Language :: Python :: 3.7
1817
Programming Language :: Python :: 3.8
1918
Programming Language :: Python :: 3.9
19+
Programming Language :: Python :: 3.10
20+
Programming Language :: Python :: 3.11
2021
License :: OSI Approved :: MIT License
2122
Topic :: Utilities
2223
Intended Audience :: Developers

src/pytest_docker/plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def execute(self, subcommand):
131131

132132
@pytest.fixture(scope="session")
133133
def docker_compose_command():
134-
"""Docker Compose command to use, it could be either `docker-compose`
135-
for Docker Compose v1 or `docker compose` for Docker Compose
136-
v2."""
134+
"""Docker Compose command to use, it could be either `docker compose`
135+
for Docker Compose V2 or `docker-compose` for Docker Compose
136+
V1."""
137137

138-
return "docker-compose"
138+
return "docker compose"
139139

140140

141141
@pytest.fixture(scope="session")

tests/test_docker_services.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_docker_services():
2222

2323
# The fixture is a context-manager.
2424
with get_docker_services(
25-
"docker-compose",
25+
"docker compose",
2626
"docker-compose.yml",
2727
docker_compose_project_name="pytest123",
2828
docker_setup=get_setup_command(),
@@ -49,17 +49,17 @@ def test_docker_services():
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 -d',
5353
stderr=subprocess.STDOUT,
5454
shell=True,
5555
),
5656
mock.call(
57-
'docker-compose -f "docker-compose.yml" -p "pytest123" port abc 123',
57+
'docker compose -f "docker-compose.yml" -p "pytest123" port abc 123',
5858
stderr=subprocess.STDOUT,
5959
shell=True,
6060
),
6161
mock.call(
62-
'docker-compose -f "docker-compose.yml" -p "pytest123" down -v',
62+
'docker compose -f "docker-compose.yml" -p "pytest123" down -v',
6363
stderr=subprocess.STDOUT,
6464
shell=True,
6565
),
@@ -77,7 +77,7 @@ def test_docker_services_unused_port():
7777

7878
# The fixture is a context-manager.
7979
with get_docker_services(
80-
"docker-compose",
80+
"docker compose",
8181
"docker-compose.yml",
8282
docker_compose_project_name="pytest123",
8383
docker_setup=get_setup_command(),
@@ -101,17 +101,17 @@ def test_docker_services_unused_port():
101101
# Both should have been called.
102102
assert check_output.call_args_list == [
103103
mock.call(
104-
'docker-compose -f "docker-compose.yml" -p "pytest123" ' "up --build -d",
104+
'docker compose -f "docker-compose.yml" -p "pytest123" ' "up --build -d",
105105
shell=True,
106106
stderr=subprocess.STDOUT,
107107
),
108108
mock.call(
109-
'docker-compose -f "docker-compose.yml" -p "pytest123" ' "port abc 123",
109+
'docker compose -f "docker-compose.yml" -p "pytest123" ' "port abc 123",
110110
shell=True,
111111
stderr=subprocess.STDOUT,
112112
),
113113
mock.call(
114-
'docker-compose -f "docker-compose.yml" -p "pytest123" down -v',
114+
'docker compose -f "docker-compose.yml" -p "pytest123" down -v',
115115
shell=True,
116116
stderr=subprocess.STDOUT,
117117
),
@@ -130,7 +130,7 @@ def test_docker_services_failure():
130130
# The fixture is a context-manager.
131131
with pytest.raises(Exception) as exc:
132132
with get_docker_services(
133-
"docker-compose",
133+
"docker compose",
134134
"docker-compose.yml",
135135
docker_compose_project_name="pytest123",
136136
docker_setup=get_setup_command(),
@@ -148,7 +148,7 @@ def test_docker_services_failure():
148148
# Tear down code should not be called.
149149
assert check_output.call_args_list == [
150150
mock.call(
151-
'docker-compose -f "docker-compose.yml" -p "pytest123" ' "up --build -d",
151+
'docker compose -f "docker-compose.yml" -p "pytest123" ' "up --build -d",
152152
shell=True,
153153
stderr=subprocess.STDOUT,
154154
)
@@ -161,7 +161,7 @@ def test_wait_until_responsive_timeout():
161161

162162
with mock.patch("time.sleep") as sleep:
163163
docker_compose = DockerComposeExecutor(
164-
compose_command="docker-compose",
164+
compose_command="docker compose",
165165
compose_files="docker-compose.yml",
166166
compose_project_name="pytest123",
167167
)

tests/test_dockercomposeexecutor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
def test_execute():
99
docker_compose = DockerComposeExecutor(
10-
"docker-compose", "docker-compose.yml", "pytest123"
10+
"docker compose", "docker-compose.yml", "pytest123"
1111
)
1212
with mock.patch("subprocess.check_output") as check_output:
1313
docker_compose.execute("up")
1414
assert check_output.call_args_list == [
1515
mock.call(
16-
'docker-compose -f "docker-compose.yml" -p "pytest123" up',
16+
'docker compose -f "docker-compose.yml" -p "pytest123" up',
1717
shell=True,
1818
stderr=subprocess.STDOUT,
1919
)
@@ -37,12 +37,12 @@ def test_execute_docker_compose_v2():
3737

3838
def test_pypath_compose_files():
3939
compose_file = py.path.local("/tmp/docker-compose.yml")
40-
docker_compose = DockerComposeExecutor("docker-compose", compose_file, "pytest123")
40+
docker_compose = DockerComposeExecutor("docker compose", compose_file, "pytest123")
4141
with mock.patch("subprocess.check_output") as check_output:
4242
docker_compose.execute("up")
4343
assert check_output.call_args_list == [
4444
mock.call(
45-
'docker-compose -f "/tmp/docker-compose.yml"' ' -p "pytest123" up',
45+
'docker compose -f "/tmp/docker-compose.yml"' ' -p "pytest123" up',
4646
shell=True,
4747
stderr=subprocess.STDOUT,
4848
)
@@ -51,13 +51,13 @@ def test_pypath_compose_files():
5151

5252
def test_multiple_compose_files():
5353
docker_compose = DockerComposeExecutor(
54-
"docker-compose", ["docker-compose.yml", "other-compose.yml"], "pytest123"
54+
"docker compose", ["docker-compose.yml", "other-compose.yml"], "pytest123"
5555
)
5656
with mock.patch("subprocess.check_output") as check_output:
5757
docker_compose.execute("up")
5858
assert check_output.call_args_list == [
5959
mock.call(
60-
'docker-compose -f "docker-compose.yml" -f "other-compose.yml"'
60+
'docker compose -f "docker-compose.yml" -f "other-compose.yml"'
6161
' -p "pytest123" up',
6262
shell=True,
6363
stderr=subprocess.STDOUT,

tests/test_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def test_docker_setup(docker_setup):
1919
assert docker_setup == "up --build -d"
2020

2121
def test_docker_compose_comand(docker_compose_command):
22-
assert docker_compose_command == "docker-compose"
22+
assert docker_compose_command == "docker compose"

0 commit comments

Comments
 (0)