pytest-docker 3.1.1__tar.gz → 3.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-3.1.1/src/pytest_docker.egg-info → pytest_docker-3.2.0}/PKG-INFO +41 -6
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/README.md +38 -4
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/setup.cfg +2 -1
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker/plugin.py +5 -4
- {pytest-docker-3.1.1 → pytest_docker-3.2.0/src/pytest_docker.egg-info}/PKG-INFO +41 -6
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/LICENSE.txt +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/pyproject.toml +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/setup.py +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker/__init__.py +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker/py.typed +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker.egg-info/SOURCES.txt +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker.egg-info/dependency_links.txt +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker.egg-info/entry_points.txt +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker.egg-info/requires.txt +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/src/pytest_docker.egg-info/top_level.txt +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/tests/test_docker_ip.py +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/tests/test_docker_services.py +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/tests/test_dockercomposeexecutor.py +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/tests/test_fixtures.py +0 -0
- {pytest-docker-3.1.1 → pytest_docker-3.2.0}/tests/test_integration.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: pytest-docker
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.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
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
17
|
Classifier: License :: OSI Approved :: MIT License
|
|
17
18
|
Classifier: Topic :: Utilities
|
|
18
19
|
Classifier: Intended Audience :: Developers
|
|
@@ -47,7 +48,7 @@ Docker-based integration tests
|
|
|
47
48
|
|
|
48
49
|
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
|
|
49
50
|
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
|
|
50
|
-
Specify all necessary containers in a `docker-compose.yml` file and
|
|
51
|
+
Specify all necessary containers in a `docker-compose.yml` file and
|
|
51
52
|
`pytest-docker` will spin them up for the duration of your tests.
|
|
52
53
|
|
|
53
54
|
`pytest-docker` was originally created by André Caron.
|
|
@@ -79,7 +80,7 @@ Another option could be usage of [`compose-switch`](https://github.com/docker/co
|
|
|
79
80
|
|
|
80
81
|
# Usage
|
|
81
82
|
|
|
82
|
-
Here is an example of a test that depends on
|
|
83
|
+
Here is an example of a test that depends on an HTTP service.
|
|
83
84
|
|
|
84
85
|
With a `docker-compose.yml` file like this (using the
|
|
85
86
|
[httpbin](https://httpbin.org/) service):
|
|
@@ -131,7 +132,7 @@ def test_status_code(http_service):
|
|
|
131
132
|
assert response.status_code == status
|
|
132
133
|
```
|
|
133
134
|
|
|
134
|
-
By default this plugin will try to open `docker-compose.yml` in your
|
|
135
|
+
By default, this plugin will try to open `docker-compose.yml` in your
|
|
135
136
|
`tests` directory. If you need to use a custom location, override the
|
|
136
137
|
`docker_compose_file` fixture inside your `conftest.py` file:
|
|
137
138
|
|
|
@@ -145,9 +146,43 @@ def docker_compose_file(pytestconfig):
|
|
|
145
146
|
return os.path.join(str(pytestconfig.rootdir), "mycustomdir", "docker-compose.yml")
|
|
146
147
|
```
|
|
147
148
|
|
|
149
|
+
To use [multiple compose files](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/),
|
|
150
|
+
return a list of paths from the `docker_compose_file` fixture:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import os
|
|
154
|
+
import pytest
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@pytest.fixture(scope="session")
|
|
158
|
+
def docker_compose_file(pytestconfig):
|
|
159
|
+
return [
|
|
160
|
+
os.path.join(str(pytestconfig.rootdir), "tests", "compose.yml"),
|
|
161
|
+
os.path.join(str(pytestconfig.rootdir), "tests", "compose.override.yml"),
|
|
162
|
+
]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
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.
|
|
166
|
+
To avoid creating multiple stacks, you can pin the project name and always teardown before starting a new stack:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
import pytest
|
|
170
|
+
|
|
171
|
+
# Pin the project name to avoid creating multiple stacks
|
|
172
|
+
@pytest.fixture(scope="session")
|
|
173
|
+
def docker_compose_project_name() -> str:
|
|
174
|
+
return "my-compose-project"
|
|
175
|
+
|
|
176
|
+
# Stop the stack before starting a new one
|
|
177
|
+
@pytest.fixture(scope="session")
|
|
178
|
+
def docker_setup_command():
|
|
179
|
+
return ["down -v", "up --build -d"]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
|
|
148
183
|
## Available fixtures
|
|
149
184
|
|
|
150
|
-
By default the scope of the fixtures are `session` but can be changed with
|
|
185
|
+
By default, the scope of the fixtures are `session` but can be changed with
|
|
151
186
|
`pytest` command line option `--container-scope <scope>`:
|
|
152
187
|
|
|
153
188
|
```bash
|
|
@@ -10,7 +10,7 @@ Docker-based integration tests
|
|
|
10
10
|
|
|
11
11
|
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
|
|
12
12
|
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
|
|
13
|
-
Specify all necessary containers in a `docker-compose.yml` file and
|
|
13
|
+
Specify all necessary containers in a `docker-compose.yml` file and
|
|
14
14
|
`pytest-docker` will spin them up for the duration of your tests.
|
|
15
15
|
|
|
16
16
|
`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
|
|
|
42
42
|
|
|
43
43
|
# Usage
|
|
44
44
|
|
|
45
|
-
Here is an example of a test that depends on
|
|
45
|
+
Here is an example of a test that depends on an HTTP service.
|
|
46
46
|
|
|
47
47
|
With a `docker-compose.yml` file like this (using the
|
|
48
48
|
[httpbin](https://httpbin.org/) service):
|
|
@@ -94,7 +94,7 @@ def test_status_code(http_service):
|
|
|
94
94
|
assert response.status_code == status
|
|
95
95
|
```
|
|
96
96
|
|
|
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
|
|
98
98
|
`tests` directory. If you need to use a custom location, override the
|
|
99
99
|
`docker_compose_file` fixture inside your `conftest.py` file:
|
|
100
100
|
|
|
@@ -108,9 +108,43 @@ def docker_compose_file(pytestconfig):
|
|
|
108
108
|
return os.path.join(str(pytestconfig.rootdir), "mycustomdir", "docker-compose.yml")
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
To use [multiple compose files](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/),
|
|
112
|
+
return a list of paths from the `docker_compose_file` fixture:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
import os
|
|
116
|
+
import pytest
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@pytest.fixture(scope="session")
|
|
120
|
+
def docker_compose_file(pytestconfig):
|
|
121
|
+
return [
|
|
122
|
+
os.path.join(str(pytestconfig.rootdir), "tests", "compose.yml"),
|
|
123
|
+
os.path.join(str(pytestconfig.rootdir), "tests", "compose.override.yml"),
|
|
124
|
+
]
|
|
125
|
+
```
|
|
126
|
+
|
|
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
|
+
|
|
111
145
|
## Available fixtures
|
|
112
146
|
|
|
113
|
-
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
|
|
114
148
|
`pytest` command line option `--container-scope <scope>`:
|
|
115
149
|
|
|
116
150
|
```bash
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = pytest-docker
|
|
3
|
-
version = 3.
|
|
3
|
+
version = 3.2.0
|
|
4
4
|
description = Simple pytest fixtures for Docker and Docker Compose based tests
|
|
5
5
|
long_description = file: README.md
|
|
6
6
|
long_description_content_type = text/markdown
|
|
@@ -16,6 +16,7 @@ classifiers =
|
|
|
16
16
|
Programming Language :: Python :: 3.10
|
|
17
17
|
Programming Language :: Python :: 3.11
|
|
18
18
|
Programming Language :: Python :: 3.12
|
|
19
|
+
Programming Language :: Python :: 3.13
|
|
19
20
|
License :: OSI Approved :: MIT License
|
|
20
21
|
Topic :: Utilities
|
|
21
22
|
Intended Audience :: Developers
|
|
@@ -21,10 +21,11 @@ def containers_scope(fixture_name: str, config: Config) -> Any: # pylint: disab
|
|
|
21
21
|
return config.getoption("--container-scope", "session")
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def execute(command: str, success_codes: Iterable[int] = (0,)) -> Union[bytes, Any]:
|
|
24
|
+
def execute(command: str, success_codes: Iterable[int] = (0,), ignore_stderr: bool = False) -> Union[bytes, Any]:
|
|
25
25
|
"""Run a shell command."""
|
|
26
26
|
try:
|
|
27
|
-
|
|
27
|
+
stderr_pipe = subprocess.DEVNULL if ignore_stderr else subprocess.STDOUT
|
|
28
|
+
output = subprocess.check_output(command, stderr=stderr_pipe, shell=True)
|
|
28
29
|
status = 0
|
|
29
30
|
except subprocess.CalledProcessError as error:
|
|
30
31
|
output = error.output or b""
|
|
@@ -132,12 +133,12 @@ class DockerComposeExecutor:
|
|
|
132
133
|
_compose_files: Any = attr.ib(converter=str_to_list)
|
|
133
134
|
_compose_project_name: str = attr.ib()
|
|
134
135
|
|
|
135
|
-
def execute(self, subcommand: str) -> Union[bytes, Any]:
|
|
136
|
+
def execute(self, subcommand: str, **kwargs: Any) -> Union[bytes, Any]:
|
|
136
137
|
command = self._compose_command
|
|
137
138
|
for compose_file in self._compose_files:
|
|
138
139
|
command += ' -f "{}"'.format(compose_file)
|
|
139
140
|
command += ' -p "{}" {}'.format(self._compose_project_name, subcommand)
|
|
140
|
-
return execute(command)
|
|
141
|
+
return execute(command, **kwargs)
|
|
141
142
|
|
|
142
143
|
|
|
143
144
|
@pytest.fixture(scope=containers_scope)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: pytest-docker
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.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
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
17
|
Classifier: License :: OSI Approved :: MIT License
|
|
17
18
|
Classifier: Topic :: Utilities
|
|
18
19
|
Classifier: Intended Audience :: Developers
|
|
@@ -47,7 +48,7 @@ Docker-based integration tests
|
|
|
47
48
|
|
|
48
49
|
Simple [pytest](http://doc.pytest.org/) fixtures that help you write integration
|
|
49
50
|
tests with Docker and [Docker Compose](https://docs.docker.com/compose/).
|
|
50
|
-
Specify all necessary containers in a `docker-compose.yml` file and
|
|
51
|
+
Specify all necessary containers in a `docker-compose.yml` file and
|
|
51
52
|
`pytest-docker` will spin them up for the duration of your tests.
|
|
52
53
|
|
|
53
54
|
`pytest-docker` was originally created by André Caron.
|
|
@@ -79,7 +80,7 @@ Another option could be usage of [`compose-switch`](https://github.com/docker/co
|
|
|
79
80
|
|
|
80
81
|
# Usage
|
|
81
82
|
|
|
82
|
-
Here is an example of a test that depends on
|
|
83
|
+
Here is an example of a test that depends on an HTTP service.
|
|
83
84
|
|
|
84
85
|
With a `docker-compose.yml` file like this (using the
|
|
85
86
|
[httpbin](https://httpbin.org/) service):
|
|
@@ -131,7 +132,7 @@ def test_status_code(http_service):
|
|
|
131
132
|
assert response.status_code == status
|
|
132
133
|
```
|
|
133
134
|
|
|
134
|
-
By default this plugin will try to open `docker-compose.yml` in your
|
|
135
|
+
By default, this plugin will try to open `docker-compose.yml` in your
|
|
135
136
|
`tests` directory. If you need to use a custom location, override the
|
|
136
137
|
`docker_compose_file` fixture inside your `conftest.py` file:
|
|
137
138
|
|
|
@@ -145,9 +146,43 @@ def docker_compose_file(pytestconfig):
|
|
|
145
146
|
return os.path.join(str(pytestconfig.rootdir), "mycustomdir", "docker-compose.yml")
|
|
146
147
|
```
|
|
147
148
|
|
|
149
|
+
To use [multiple compose files](https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/),
|
|
150
|
+
return a list of paths from the `docker_compose_file` fixture:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import os
|
|
154
|
+
import pytest
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@pytest.fixture(scope="session")
|
|
158
|
+
def docker_compose_file(pytestconfig):
|
|
159
|
+
return [
|
|
160
|
+
os.path.join(str(pytestconfig.rootdir), "tests", "compose.yml"),
|
|
161
|
+
os.path.join(str(pytestconfig.rootdir), "tests", "compose.override.yml"),
|
|
162
|
+
]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
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.
|
|
166
|
+
To avoid creating multiple stacks, you can pin the project name and always teardown before starting a new stack:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
import pytest
|
|
170
|
+
|
|
171
|
+
# Pin the project name to avoid creating multiple stacks
|
|
172
|
+
@pytest.fixture(scope="session")
|
|
173
|
+
def docker_compose_project_name() -> str:
|
|
174
|
+
return "my-compose-project"
|
|
175
|
+
|
|
176
|
+
# Stop the stack before starting a new one
|
|
177
|
+
@pytest.fixture(scope="session")
|
|
178
|
+
def docker_setup_command():
|
|
179
|
+
return ["down -v", "up --build -d"]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
|
|
148
183
|
## Available fixtures
|
|
149
184
|
|
|
150
|
-
By default the scope of the fixtures are `session` but can be changed with
|
|
185
|
+
By default, the scope of the fixtures are `session` but can be changed with
|
|
151
186
|
`pytest` command line option `--container-scope <scope>`:
|
|
152
187
|
|
|
153
188
|
```bash
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|