Skip to content

Commit

Permalink
feat!: V2 as default
Browse files Browse the repository at this point in the history
  • Loading branch information
augi committed Jul 19, 2023
1 parent 519b155 commit f022dcb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 2.0.0
Breaking changes:
- Default command changed from `docker-compose` to `docker compose`, so the V2 is the default one.

## Version 1.0.1
Chore:
- Set dependency on `attrs` to be the same as in `pytest`
Expand Down
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Docker-based integration tests

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

Expand All @@ -18,11 +18,9 @@ This package is tested with Python versions `3.6`, `3.7`, `3.8` and
`pytest-docker` was originally created by André Caron.

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

By default, it uses the `docker compose` command, so it relies on the Compose plugin for Docker (also called Docker Compose V2).

The default behavior is not to install `docker-compose` with `pytest-docker`. If you
want to, you install `pytest-docker` with the `docker-compose-v1`
Expand All @@ -32,16 +30,23 @@ extra. You can use the following command:
pip install pytest-docker[docker-compose-v1]
```

## Docker Compose v2 compatiblity
## Docker Compose V1 compatibility

If you want to use the old `docker-compose` command (deprecated since July 2023, not receiving updates since 2021)
then you can do it using the [`docker-compose-command`](#docker_compose_command) fixture:

`pytest-docker` will work with Docker Compose v2 out of the box if
[`compose-switch`](https://github.com/docker/compose-switch)
is installed.
```python
@pytest.fixture(scope="session")
def docker_compose_command() -> str:
return "docker-compose"
```

If you want to use the pip-distributed version of `docker-compose` command, you can install it using
```
pip install pytest-docker[docker-compose-v1]
```

If you want to use the real Docker Compose v2, it has to be installed
system wide ([more information](https://github.com/docker/compose#linux))
and you have to modify the [`docker-compose-command`](#docker_compose_command)
fixture (this behavior might change in the future versions).
Another option could be usage of [`compose-switch`](https://github.com/docker/compose-switch).

# Usage
Here is an example of a test that depends on a HTTP service.
Expand Down Expand Up @@ -135,8 +140,8 @@ After test are finished, shutdown all services (`docker-compose down`).
### `docker_compose_command`

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

### `docker_setup`

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = pytest-docker
version = 1.0.1
description = Simple pytest fixtures for Docker and docker-compose based tests
description = Simple pytest fixtures for Docker and Docker Compose based tests
long_description = file: README.md
long_description_content_type = text/markdown
keywords = docker,docker-compose,pytest
Expand Down
8 changes: 4 additions & 4 deletions src/pytest_docker/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def execute(self, subcommand):

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

return "docker-compose"
return "docker compose"


@pytest.fixture(scope="session")
Expand Down

0 comments on commit f022dcb

Please sign in to comment.