Skip to content

Commit dfef46d

Browse files
jeltheraugi
authored andcommitted
Added an example on how to reuse the project name to make it easier to debug tests.
1 parent bdf164d commit dfef46d

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Docker-based integration tests
1010

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

1616
`pytest-docker` was originally created by André Caron.
@@ -42,7 +42,7 @@ Another option could be usage of [`compose-switch`](https://github.com/docker/co
4242

4343
# Usage
4444

45-
Here is an example of a test that depends on a HTTP service.
45+
Here is an example of a test that depends on an HTTP service.
4646

4747
With a `docker-compose.yml` file like this (using the
4848
[httpbin](https://httpbin.org/) service):
@@ -94,7 +94,7 @@ def test_status_code(http_service):
9494
assert response.status_code == status
9595
```
9696
97-
By default this plugin will try to open `docker-compose.yml` in your
97+
By default, this plugin will try to open `docker-compose.yml` in your
9898
`tests` directory. If you need to use a custom location, override the
9999
`docker_compose_file` fixture inside your `conftest.py` file:
100100

@@ -124,9 +124,27 @@ def docker_compose_file(pytestconfig):
124124
]
125125
```
126126

127+
If you want to debug the test suite in your IDE (Pycharm, VsCode, etc.) and need to stop the test, the stack will be left running.
128+
To avoid creating multiple stacks, you can pin the project name and always teardown before starting a new stack:
129+
130+
```python
131+
import pytest
132+
133+
# Pin the project name to avoid creating multiple stacks
134+
@pytest.fixture(scope="session")
135+
def docker_compose_project_name() -> str:
136+
return "my-compose-project"
137+
138+
# Stop the stack before starting a new one
139+
@pytest.fixture(scope="session")
140+
def docker_setup_command():
141+
return ["down -v", "up --build -d"]
142+
```
143+
144+
127145
## Available fixtures
128146

129-
By default the scope of the fixtures are `session` but can be changed with
147+
By default, the scope of the fixtures are `session` but can be changed with
130148
`pytest` command line option `--container-scope <scope>`:
131149

132150
```bash

0 commit comments

Comments
 (0)