pytest-docker-compose-v2 0.1.2__tar.gz → 0.3.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_compose_v2-0.3.0/.devcontainer/Dockerfile +76 -0
- pytest_docker_compose_v2-0.3.0/.devcontainer/devcontainer.json +80 -0
- pytest_docker_compose_v2-0.3.0/.github/workflows/release.yaml +40 -0
- pytest_docker_compose_v2-0.3.0/.github/workflows/test.yaml +50 -0
- pytest_docker_compose_v2-0.3.0/.gitignore +123 -0
- pytest_docker_compose_v2-0.3.0/Justfile +76 -0
- pytest-docker-compose-v2-0.1.2/README.md → pytest_docker_compose_v2-0.3.0/PKG-INFO +127 -17
- pytest-docker-compose-v2-0.1.2/PKG-INFO → pytest_docker_compose_v2-0.3.0/README.md +99 -40
- pytest_docker_compose_v2-0.3.0/pyproject.toml +128 -0
- pytest_docker_compose_v2-0.3.0/pytest_docker_compose/__init__.py +1 -0
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/pytest_docker_compose/plugin.py +58 -34
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/my_network/a_buildable_container/an_api.py +23 -22
- pytest_docker_compose_v2-0.3.0/tests/pytest_docker_compose_tests/my_network/a_buildable_container/requirements.txt +3 -0
- pytest_docker_compose_v2-0.3.0/tests/pytest_docker_compose_tests/my_network/docker-compose.yml +33 -0
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/test_function_scoping_fixtures.py +0 -3
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/test_module_scoping_fixtures.py +0 -3
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/test_multiple_compose_files.py +0 -2
- pytest_docker_compose_v2-0.3.0/tests/pytest_docker_compose_tests/test_wait_for_healthcheck.py +48 -0
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/test_wrong_scoping.py +0 -2
- pytest_docker_compose_v2-0.3.0/uv.lock +1261 -0
- pytest-docker-compose-v2-0.1.2/pyproject.toml +0 -101
- pytest-docker-compose-v2-0.1.2/pytest_docker_compose/__init__.py +0 -1
- pytest-docker-compose-v2-0.1.2/tests/pytest_docker_compose_tests/my_network/a_buildable_container/requirements.txt +0 -3
- pytest-docker-compose-v2-0.1.2/tests/pytest_docker_compose_tests/my_network/docker-compose.yml +0 -16
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/LICENSE +0 -0
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/my_network/a_buildable_container/Dockerfile +0 -0
- {pytest-docker-compose-v2-0.1.2 → pytest_docker_compose_v2-0.3.0}/tests/pytest_docker_compose_tests/my_network/extra-service.yml +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
FROM python:3.11.8-bookworm
|
|
2
|
+
|
|
3
|
+
ARG DEBIAN_FRONTEND=noninteractive
|
|
4
|
+
ARG UID=1000
|
|
5
|
+
ARG GID=1000
|
|
6
|
+
ARG DEV_USER=dev
|
|
7
|
+
ARG BUILD_DIR=/tmp/build
|
|
8
|
+
|
|
9
|
+
ENV VIRTUAL_ENV=/venv
|
|
10
|
+
ENV LC_ALL en_US.UTF-8
|
|
11
|
+
ENV LANG en_US.UTF-8
|
|
12
|
+
ENV LANGUAGE en_US.UTF-8
|
|
13
|
+
|
|
14
|
+
RUN apt-get update \
|
|
15
|
+
&& apt-get install -yq --no-install-recommends \
|
|
16
|
+
# useful OS packages
|
|
17
|
+
sudo \
|
|
18
|
+
locales \
|
|
19
|
+
locales-all \
|
|
20
|
+
build-essential \
|
|
21
|
+
openssh-client \
|
|
22
|
+
rsync \
|
|
23
|
+
iputils-ping \
|
|
24
|
+
wget \
|
|
25
|
+
git \
|
|
26
|
+
ripgrep \
|
|
27
|
+
unzip \
|
|
28
|
+
curl \
|
|
29
|
+
vim \
|
|
30
|
+
bash-completion \
|
|
31
|
+
man-db \
|
|
32
|
+
less \
|
|
33
|
+
# Docker CE CLI and other packages
|
|
34
|
+
apt-transport-https \
|
|
35
|
+
ca-certificates \
|
|
36
|
+
&& rm -rf /var/lib/apt/lists/* \
|
|
37
|
+
&& update-ca-certificates
|
|
38
|
+
|
|
39
|
+
RUN addgroup --gid ${GID} ${DEV_USER} \
|
|
40
|
+
&& adduser --disabled-password --gecos '' --uid ${UID} --gid ${GID} ${DEV_USER} \
|
|
41
|
+
&& mkdir -p /etc/sudoers.d \
|
|
42
|
+
&& echo ${DEV_USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${DEV_USER} \
|
|
43
|
+
&& chmod 0440 /etc/sudoers.d/${DEV_USER} \
|
|
44
|
+
&& mkdir -p /home/${DEV_USER} \
|
|
45
|
+
&& mkdir -p /home/${DEV_USER}/.vscode-server/extensions \
|
|
46
|
+
&& mkdir -p /home/${DEV_USER}/.vscode-server-insiders/extensions \
|
|
47
|
+
&& chown -R ${DEV_USER}:${DEV_USER} /home/${DEV_USER}
|
|
48
|
+
|
|
49
|
+
# install node
|
|
50
|
+
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
|
|
51
|
+
RUN apt-get update \
|
|
52
|
+
&& apt-get install -yq --no-install-recommends \
|
|
53
|
+
nodejs \
|
|
54
|
+
&& rm -rf /var/lib/apt/lists/* \
|
|
55
|
+
&& update-ca-certificates
|
|
56
|
+
|
|
57
|
+
# install devcontainer cli tool so we can build and push devcontainer from itself
|
|
58
|
+
RUN npm install -g @devcontainers/cli
|
|
59
|
+
RUN mkdir ${VIRTUAL_ENV} && chown ${UID}:${GID} ${VIRTUAL_ENV}
|
|
60
|
+
|
|
61
|
+
# install uv
|
|
62
|
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
|
63
|
+
|
|
64
|
+
USER ${DEV_USER}
|
|
65
|
+
|
|
66
|
+
ENV PATH "/home/${DEV_USER}/.local/bin:${PATH}"
|
|
67
|
+
|
|
68
|
+
# install dependencies into virtualenv
|
|
69
|
+
WORKDIR ${BUILD_DIR}
|
|
70
|
+
RUN uv venv ${VIRTUAL_ENV}
|
|
71
|
+
COPY pyproject.toml uv.lock README.md ${BUILD_DIR}
|
|
72
|
+
RUN uv sync --locked
|
|
73
|
+
|
|
74
|
+
WORKDIR /workspace
|
|
75
|
+
|
|
76
|
+
LABEL org.opencontainers.image.source https://github.com/radusuciu/pytest-docker-compose-v2
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pytest docker compose v2 Development",
|
|
3
|
+
"build": {
|
|
4
|
+
"dockerfile": "Dockerfile",
|
|
5
|
+
"context": "${localWorkspaceFolder}"
|
|
6
|
+
},
|
|
7
|
+
// needed because of the interaction between the devcontainer
|
|
8
|
+
// the test docker compose project, and the hostname reported by
|
|
9
|
+
// docker inspect in the tests in the PortConfig.
|
|
10
|
+
// the hostname is 0.0.0.0 and cannot be reached by the test code
|
|
11
|
+
// unless the devcontainer is on the host network. I've tried, among
|
|
12
|
+
// many othe permutations, putting the devcontainer on the same
|
|
13
|
+
// externally created network as the test containers but that did
|
|
14
|
+
// not work
|
|
15
|
+
"runArgs": [
|
|
16
|
+
"--network=host"
|
|
17
|
+
],
|
|
18
|
+
"workspaceFolder": "/workspace",
|
|
19
|
+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
|
|
20
|
+
"mounts": [
|
|
21
|
+
{
|
|
22
|
+
"source": "/var/run/docker.sock",
|
|
23
|
+
"target": "/var/run/docker.sock",
|
|
24
|
+
"type": "bind"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
// Set *default* container specific settings.json values on container create.
|
|
28
|
+
"customizations": {
|
|
29
|
+
"vscode": {
|
|
30
|
+
"extensions": [
|
|
31
|
+
"ms-python.python",
|
|
32
|
+
"charliermarsh.ruff",
|
|
33
|
+
"ms-azuretools.vscode-docker",
|
|
34
|
+
"eamodio.gitlens",
|
|
35
|
+
"Gruntfuggly.todo-tree",
|
|
36
|
+
"be5invis.toml",
|
|
37
|
+
"GitHub.vscode-github-actions",
|
|
38
|
+
"GitHub.copilot",
|
|
39
|
+
"GitHub.vscode-pull-request-github"
|
|
40
|
+
],
|
|
41
|
+
"settings": {
|
|
42
|
+
"#terminal.integrated.defaultProfile.linux#": "/bin/bash",
|
|
43
|
+
"python.defaultInterpreterPath": "/venv/bin/python",
|
|
44
|
+
"python.terminal.activateEnvironment": true,
|
|
45
|
+
"python.testing.unittestEnabled": false,
|
|
46
|
+
"python.testing.nosetestsEnabled": false,
|
|
47
|
+
"python.testing.pytestEnabled": true,
|
|
48
|
+
"ruff.organizeImports": true,
|
|
49
|
+
"[python]": {
|
|
50
|
+
"editor.codeActionsOnSave": {
|
|
51
|
+
"source.organizeImports": "always"
|
|
52
|
+
},
|
|
53
|
+
"editor.defaultFormatter": "charliermarsh.ruff",
|
|
54
|
+
"editor.formatOnSave": true
|
|
55
|
+
},
|
|
56
|
+
"[dockerfile]": {
|
|
57
|
+
"editor.formatOnSave": false
|
|
58
|
+
},
|
|
59
|
+
"dev.containers.dockerCredentialHelper": false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"features": {
|
|
64
|
+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
|
|
65
|
+
"ghcr.io/devcontainers/features/github-cli:1": {}
|
|
66
|
+
},
|
|
67
|
+
"remoteEnv": {
|
|
68
|
+
// Pass in the host directory for Docker mount commands from inside the container
|
|
69
|
+
"HOST_PROJECT_PATH": "${localWorkspaceFolder}",
|
|
70
|
+
"VIRTUAL_ENV": "/venv",
|
|
71
|
+
"PATH": "${containerEnv:PATH}:/venv/bin",
|
|
72
|
+
"EDITOR": "code --wait",
|
|
73
|
+
"VISUAL": "code --wait",
|
|
74
|
+
"GIT_EDITOR": "code --wait"
|
|
75
|
+
},
|
|
76
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
77
|
+
// Left empty because this is handled by docker compose for individual services,
|
|
78
|
+
// use this only for additional ports not needed by those services (e.g. ssh)
|
|
79
|
+
"forwardPorts": []
|
|
80
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- '*.*.*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-and-publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi-publish
|
|
12
|
+
permissions:
|
|
13
|
+
# for creating github release
|
|
14
|
+
contents: write
|
|
15
|
+
# for trusted publishing
|
|
16
|
+
id-token: write
|
|
17
|
+
steps:
|
|
18
|
+
- name: Check out repository
|
|
19
|
+
uses: actions/checkout@v7
|
|
20
|
+
- name: Set up uv
|
|
21
|
+
uses: astral-sh/setup-uv@v10.2.0
|
|
22
|
+
with:
|
|
23
|
+
enable-cache: true
|
|
24
|
+
python-version: '3.13'
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: uv run pytest
|
|
30
|
+
- name: Create GitHub release
|
|
31
|
+
uses: softprops/action-gh-release@v3
|
|
32
|
+
with:
|
|
33
|
+
name: Release ${{ github.ref }}
|
|
34
|
+
tag_name: ${{ github.ref }}
|
|
35
|
+
draft: false
|
|
36
|
+
prerelease: false
|
|
37
|
+
- name: Build package
|
|
38
|
+
run: uv build
|
|
39
|
+
- name: Publish to PyPI
|
|
40
|
+
run: uv publish
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- develop
|
|
8
|
+
pull_request:
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
|
|
18
|
+
pytest-version: ['7', '8', '9']
|
|
19
|
+
steps:
|
|
20
|
+
- name: Check out repository
|
|
21
|
+
uses: actions/checkout@v7
|
|
22
|
+
# needed because we use git describe to get a bumpver compatible GITHASH containing version
|
|
23
|
+
# alternatively can look at using HEXHASH instead. Note that these are purposefully not
|
|
24
|
+
# documented in the bumpver project, see issues/PRs for more info.
|
|
25
|
+
# with:
|
|
26
|
+
# fetch-depth: 0
|
|
27
|
+
- name: Set up uv
|
|
28
|
+
uses: astral-sh/setup-uv@v10.2.0
|
|
29
|
+
with:
|
|
30
|
+
enable-cache: true
|
|
31
|
+
python-version: ${{ matrix.python-version }}
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: uv sync
|
|
34
|
+
- name: Install pytest ${{ matrix.pytest-version }}
|
|
35
|
+
run: uv pip install "pytest>=${{ matrix.pytest-version }},<$(( ${{ matrix.pytest-version }} + 1 ))"
|
|
36
|
+
- name: Run tests
|
|
37
|
+
run: uv run --no-sync pytest
|
|
38
|
+
- name: Run healthcheck wait tests
|
|
39
|
+
run: uv run --no-sync pytest -m wait_for_healthcheck --docker-compose ./tests/pytest_docker_compose_tests/my_network --docker-compose-wait
|
|
40
|
+
# NOTE: publishing to test repository is disabled until I figure out a way to do it reliably
|
|
41
|
+
# this means that we need to avoid version clashes as well as local versions
|
|
42
|
+
# see: https://github.com/pypa/packaging.python.org/issues/804
|
|
43
|
+
# - name: Publish to test repository
|
|
44
|
+
# if: matrix.python-version == '3.11'
|
|
45
|
+
# run: |
|
|
46
|
+
# # adding the git hash to the current version so that the package
|
|
47
|
+
# # won't be rejected from the test repository due to version clash
|
|
48
|
+
# TEMP_VERSION=$(git describe | sed s/\-/\./ | sed s/\-/\+/)
|
|
49
|
+
# uv run bumpver update --no-commit --no-tag-commit --set-version="${TEMP_VERSION}"
|
|
50
|
+
# uv publish --index testpypi
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
|
|
53
|
+
# Translations
|
|
54
|
+
*.mo
|
|
55
|
+
*.pot
|
|
56
|
+
|
|
57
|
+
# Django stuff:
|
|
58
|
+
*.log
|
|
59
|
+
local_settings.py
|
|
60
|
+
db.sqlite3
|
|
61
|
+
|
|
62
|
+
# Flask stuff:
|
|
63
|
+
instance/
|
|
64
|
+
.webassets-cache
|
|
65
|
+
|
|
66
|
+
# Scrapy stuff:
|
|
67
|
+
.scrapy
|
|
68
|
+
|
|
69
|
+
# Sphinx documentation
|
|
70
|
+
docs/_build/
|
|
71
|
+
|
|
72
|
+
# PyBuilder
|
|
73
|
+
target/
|
|
74
|
+
|
|
75
|
+
# Jupyter Notebook
|
|
76
|
+
.ipynb_checkpoints
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
87
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
88
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
89
|
+
# install all needed dependencies.
|
|
90
|
+
#Pipfile.lock
|
|
91
|
+
|
|
92
|
+
# celery beat schedule file
|
|
93
|
+
celerybeat-schedule
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
set shell := ["bash", "-euo", "pipefail", "-c"]
|
|
2
|
+
|
|
3
|
+
# Generate Markdown release notes for VERSION without modifying the repository.
|
|
4
|
+
release-notes version:
|
|
5
|
+
#!/usr/bin/env bash
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
version="{{ version }}"
|
|
9
|
+
if git show-ref --verify --quiet "refs/tags/${version}"; then
|
|
10
|
+
revision="${version}"
|
|
11
|
+
previous="$(git describe --tags --abbrev=0 "${version}^")"
|
|
12
|
+
else
|
|
13
|
+
revision="HEAD"
|
|
14
|
+
previous="$(git describe --tags --abbrev=0 HEAD)"
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
uv run git-cliff "${previous}..${revision}" \
|
|
18
|
+
--tag "${version}" \
|
|
19
|
+
--config keepachangelog \
|
|
20
|
+
--strip all
|
|
21
|
+
|
|
22
|
+
# Add generated notes to an existing GitHub release (requires the GitHub CLI).
|
|
23
|
+
publish-release-notes version:
|
|
24
|
+
#!/usr/bin/env bash
|
|
25
|
+
set -euo pipefail
|
|
26
|
+
|
|
27
|
+
command -v gh >/dev/null || {
|
|
28
|
+
echo "The GitHub CLI (gh) is required to publish release notes." >&2
|
|
29
|
+
exit 1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
notes_file="$(mktemp)"
|
|
33
|
+
trap 'rm -f "${notes_file}"' EXIT
|
|
34
|
+
uv run just release-notes "{{ version }}" > "${notes_file}"
|
|
35
|
+
gh release edit "{{ version }}" --notes-file "${notes_file}"
|
|
36
|
+
|
|
37
|
+
# Bump VERSION_KIND (patch, minor, or major), commit, tag, and push the release.
|
|
38
|
+
release version_kind:
|
|
39
|
+
#!/usr/bin/env bash
|
|
40
|
+
set -euo pipefail
|
|
41
|
+
|
|
42
|
+
version_kind="{{ version_kind }}"
|
|
43
|
+
case "${version_kind}" in
|
|
44
|
+
patch|minor|major) ;;
|
|
45
|
+
*)
|
|
46
|
+
echo "Version kind must be one of: patch, minor, major." >&2
|
|
47
|
+
exit 2
|
|
48
|
+
;;
|
|
49
|
+
esac
|
|
50
|
+
|
|
51
|
+
if [[ "$(git branch --show-current)" != "main" ]]; then
|
|
52
|
+
echo "Releases must be created from the main branch." >&2
|
|
53
|
+
exit 1
|
|
54
|
+
fi
|
|
55
|
+
if [[ -n "$(git status --porcelain)" ]]; then
|
|
56
|
+
echo "The working tree must be clean before creating a release." >&2
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
git fetch origin main --tags
|
|
61
|
+
if [[ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]]; then
|
|
62
|
+
echo "Local main must match origin/main before creating a release." >&2
|
|
63
|
+
exit 1
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
uv run pytest
|
|
67
|
+
uv run bumpver update "--${version_kind}" --ignore-vcs-tag --no-fetch
|
|
68
|
+
version="$(uv run python -c 'from pytest_docker_compose import __version__; print(__version__)')"
|
|
69
|
+
|
|
70
|
+
uv run just release-notes "${version}"
|
|
71
|
+
git push origin main
|
|
72
|
+
git push origin "${version}"
|
|
73
|
+
|
|
74
|
+
echo
|
|
75
|
+
echo "Release ${version} pushed. Once GitHub creates the release, publish its notes with:"
|
|
76
|
+
echo " uv run just publish-release-notes ${version}"
|
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-docker-compose-v2
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Manages Docker containers during your integration tests
|
|
5
|
+
Project-URL: repository, https://github.com/radusuciu/pytest-docker-compose-v2
|
|
6
|
+
Author: Radu Suciu, Thomas Meckel, Roald Storm, Phoenix Zerin
|
|
7
|
+
License: Apache
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: docker compose,pytest
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Framework :: Pytest
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: pytest<10,>=7.2.2
|
|
25
|
+
Requires-Dist: python-on-whales<1,>=0.71.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
1
28
|
[](https://pypi.python.org/pypi/pytest-docker-compose-v2/)
|
|
2
29
|
[](https://pypi.python.org/pypi/pytest-docker-compose-v2/)
|
|
3
30
|
[](https://github.com/radusuciu/pytest-docker-compose-v2/releases/)
|
|
@@ -17,8 +44,8 @@ Make sure you have [Docker](https://docs.docker.com/get-docker/) installed.
|
|
|
17
44
|
|
|
18
45
|
This plugin is automatically tested against the following software:
|
|
19
46
|
|
|
20
|
-
- Python 3.
|
|
21
|
-
- pytest 7
|
|
47
|
+
- Python 3.10, 3.11, 3.12, 3.13 and 3.14
|
|
48
|
+
- pytest 7, 8 and 9
|
|
22
49
|
|
|
23
50
|
**NOTE**: This plugin is **not** compatible with Python 2.
|
|
24
51
|
|
|
@@ -33,20 +60,17 @@ pip install pytest-docker-compose-v2
|
|
|
33
60
|
|
|
34
61
|
## Usage
|
|
35
62
|
|
|
36
|
-
|
|
63
|
+
The plugin is automatically enabled when installed. To disable it for specific test runs, use:
|
|
37
64
|
|
|
38
|
-
```
|
|
39
|
-
|
|
65
|
+
```shell
|
|
66
|
+
pytest -p no:docker_compose
|
|
40
67
|
```
|
|
41
68
|
|
|
42
|
-
|
|
43
|
-
See [Installing and Using Plugins](https://docs.pytest.org/en/latest/plugins.html#requiring-loading-plugins-in-a-test-module-or-conftest-file) for more information.
|
|
44
|
-
|
|
45
|
-
To interact with Docker containers in your tests, use the following fixtures, these fixtures tell docker-compose to start all the services and then they can fetch the associated containers for use in a test:
|
|
69
|
+
To interact with Docker containers in your tests, use the following fixtures. These fixtures tell docker-compose to start all the services and then fetch the associated containers for use in a test:
|
|
46
70
|
|
|
47
71
|
### `function_scoped_container_getter`
|
|
48
72
|
|
|
49
|
-
An object that fetches containers of the Docker `
|
|
73
|
+
An object that fetches containers of the Docker `python_on_whales.Container` objects running during the test. The containers are fetched using `function_scoped_container_getter.get('service_name')` These containers each have an extra attribute called `network_info` added to them. This attribute has a list of `pytest_docker_compose.NetworkInfo` objects.
|
|
50
74
|
|
|
51
75
|
This information can be used to configure API clients and other objects that will connect to services exposed by the Docker containers in your tests.
|
|
52
76
|
|
|
@@ -62,12 +86,12 @@ This information can be used to configure API clients and other objects that wil
|
|
|
62
86
|
|
|
63
87
|
### `docker_project`
|
|
64
88
|
|
|
65
|
-
The `
|
|
89
|
+
The `python_on_whales.DockerClient` object that the containers are built from.
|
|
66
90
|
This fixture is generally only used internally by the plugin.
|
|
67
91
|
|
|
68
92
|
### Wider scoped fixtures
|
|
69
93
|
|
|
70
|
-
To use the following fixtures please read [Use wider scoped fixtures](#use-wider-
|
|
94
|
+
To use the following fixtures please read [Use wider scoped fixtures](#use-wider-scoped-fixtures)
|
|
71
95
|
|
|
72
96
|
- `class_scoped_container_getter`: Similar to `function_scoped_container_getter` just with a wider scope.
|
|
73
97
|
- `module_scoped_container_getter`: Similar to `function_scoped_container_getter` just with a wider scope.
|
|
@@ -79,7 +103,53 @@ The fixtures called `[scope]_scoped_container_getter` will wait until every cont
|
|
|
79
103
|
|
|
80
104
|
However, just because a container is up does not mean that the services running on it are ready to accept incoming requests yet!
|
|
81
105
|
|
|
82
|
-
|
|
106
|
+
#### Option 1: Using Docker Compose Healthchecks (Recommended)
|
|
107
|
+
|
|
108
|
+
The plugin can use Docker Compose's native `--wait` functionality with healthchecks defined in your `docker-compose.yml`. This lets Docker Compose handle waiting for services to be ready.
|
|
109
|
+
|
|
110
|
+
First, define healthchecks in your `docker-compose.yml`:
|
|
111
|
+
|
|
112
|
+
```yaml
|
|
113
|
+
services:
|
|
114
|
+
my_api_service:
|
|
115
|
+
build: ./api
|
|
116
|
+
ports:
|
|
117
|
+
- "5000:5000"
|
|
118
|
+
depends_on:
|
|
119
|
+
my_db:
|
|
120
|
+
condition: service_healthy
|
|
121
|
+
healthcheck:
|
|
122
|
+
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
|
|
123
|
+
interval: 5s
|
|
124
|
+
timeout: 5s
|
|
125
|
+
retries: 10
|
|
126
|
+
start_period: 10s
|
|
127
|
+
my_db:
|
|
128
|
+
image: postgres:15
|
|
129
|
+
healthcheck:
|
|
130
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
131
|
+
interval: 5s
|
|
132
|
+
timeout: 5s
|
|
133
|
+
retries: 10
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Then opt in to waiting when you run pytest:
|
|
137
|
+
|
|
138
|
+
```shell
|
|
139
|
+
pytest --docker-compose-wait
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
You can also specify a timeout (in seconds):
|
|
143
|
+
|
|
144
|
+
```shell
|
|
145
|
+
pytest --docker-compose-wait --docker-compose-wait-timeout=120
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Waiting remains opt-in for backward compatibility. It is planned to become the default in version 1.0.
|
|
149
|
+
|
|
150
|
+
#### Option 2: Python-based Wait Fixtures
|
|
151
|
+
|
|
152
|
+
If your tests need to wait for a particular condition (for example, to wait for an HTTP health check endpoint to send back a 200 response), you can implement custom wait logic in your fixtures.
|
|
83
153
|
|
|
84
154
|
Here's an example of a fixture called `wait_for_api` that waits for an HTTP service to come online before a test called `test_read_and_write` can run.
|
|
85
155
|
|
|
@@ -90,8 +160,6 @@ from urllib.parse import urljoin
|
|
|
90
160
|
from urllib3.util.retry import Retry
|
|
91
161
|
from requests.adapters import HTTPAdapter
|
|
92
162
|
|
|
93
|
-
pytest_plugins = ["docker_compose"]
|
|
94
|
-
|
|
95
163
|
# Invoking this fixture: 'function_scoped_container_getter' starts all services
|
|
96
164
|
@pytest.fixture(scope="function")
|
|
97
165
|
def wait_for_api(function_scoped_container_getter):
|
|
@@ -137,7 +205,7 @@ pytest --use-running-containers
|
|
|
137
205
|
|
|
138
206
|
With this flag, `pytest-docker-compose` checks that all containers are running
|
|
139
207
|
during the project creation. If they are not running a warning is given and
|
|
140
|
-
they are spun up anyways. They are then used for all the tests and NOT
|
|
208
|
+
they are spun up anyways. They are then used for all the tests and NOT TORN
|
|
141
209
|
DOWN afterwards.
|
|
142
210
|
|
|
143
211
|
This mode is best used in combination with the `--docker-compose-no-build` flag since the newly build containers won't be used anyways. like so:
|
|
@@ -186,7 +254,7 @@ addopts = --docker-compose=/path/to/docker-compose.yml
|
|
|
186
254
|
|
|
187
255
|
The option will be ignored for tests that do not use this plugin.
|
|
188
256
|
|
|
189
|
-
See [Configuration Options](https://docs.pytest.org/en/
|
|
257
|
+
See [Configuration Options](https://docs.pytest.org/en/stable/reference/customize.html#adding-default-options) for more information on using configuration
|
|
190
258
|
files to modify pytest behavior.
|
|
191
259
|
|
|
192
260
|
### Remove volumes after tests
|
|
@@ -199,5 +267,47 @@ pytest --docker-compose-remove-volumes
|
|
|
199
267
|
|
|
200
268
|
This option will be ignored if the plugin is not used. Again, this option can also be added to the `pytest.ini` file.
|
|
201
269
|
|
|
270
|
+
### Command Line Options Summary
|
|
271
|
+
|
|
272
|
+
| Option | Description |
|
|
273
|
+
|--------|-------------|
|
|
274
|
+
| `--docker-compose` | Path to docker-compose.yml file or directory containing one. Multiple files can be specified with commas. |
|
|
275
|
+
| `--docker-compose-no-build` | Skip building Docker images before running tests. |
|
|
276
|
+
| `--docker-compose-remove-volumes` | Remove container volumes after tests complete. |
|
|
277
|
+
| `--use-running-containers` | Use already running containers instead of starting new ones. |
|
|
278
|
+
| `--docker-compose-wait` | Wait for services to be healthy before running tests (requires healthcheck definitions). |
|
|
279
|
+
| `--docker-compose-wait-timeout` | Timeout in seconds when waiting for services to be healthy. |
|
|
280
|
+
|
|
202
281
|
For more examples on how to use this plugin look at the testing suite of this plugin itself! It will give you some examples for configuring `pyproject.toml` and how to use the different fixtures to run docker containers.
|
|
203
282
|
|
|
283
|
+
## Releasing
|
|
284
|
+
|
|
285
|
+
Release commands are managed with `just`, which is installed by the development
|
|
286
|
+
dependency group:
|
|
287
|
+
|
|
288
|
+
```shell
|
|
289
|
+
uv sync
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Preview the release notes for a version without modifying the repository:
|
|
293
|
+
|
|
294
|
+
```shell
|
|
295
|
+
uv run just release-notes 0.3.0
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Create and push a release from a clean, up-to-date `main` branch by choosing a
|
|
299
|
+
semantic version increment:
|
|
300
|
+
|
|
301
|
+
```shell
|
|
302
|
+
uv run just release patch
|
|
303
|
+
uv run just release minor
|
|
304
|
+
uv run just release major
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The command runs the tests, updates the package version, creates the version
|
|
308
|
+
commit and tag, and pushes both. Once GitHub Actions has created the GitHub
|
|
309
|
+
Release, its generated notes can be added with:
|
|
310
|
+
|
|
311
|
+
```shell
|
|
312
|
+
uv run just publish-release-notes 0.3.0
|
|
313
|
+
```
|