Skip to content

Commit 6d5b745

Browse files
Simplify test infrastructure to use docker-compose services
Replace pytest-managed Docker containers with external docker-compose services. This removes complexity, improves reliability, and allows running tests both from the host machine and inside the devcontainer. - Remove docker container lifecycle management from conftest.py - Add pixi tasks for running tests (services-up, test, test-cov) - Expose MySQL and MinIO ports in docker-compose.yaml for host access - Simplify devcontainer to extend the main docker-compose.yaml - Remove docker dependency from test requirements 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c951ee5 commit 6d5b745

File tree

5 files changed

+197
-476
lines changed

5 files changed

+197
-476
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
3-
"features": {
4-
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
5-
},
2+
"dockerComposeFile": ["../docker-compose.yaml", "docker-compose.yml"],
3+
"service": "app",
4+
"workspaceFolder": "/src",
65
"postCreateCommand": "curl -fsSL https://pixi.sh/install.sh | bash && echo 'export PATH=\"$HOME/.pixi/bin:$PATH\"' >> ~/.bashrc"
7-
}
6+
}

.devcontainer/docker-compose.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1+
# Devcontainer overrides for the app service from ../docker-compose.yaml
2+
# Inherits db and minio services automatically
13
services:
2-
# Update this to the name of the service you want to work with in your docker-compose.yml file
34
app:
4-
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
5-
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
6-
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
7-
# array). The sample below assumes your primary file is in the root of your project.
85
container_name: datajoint-python-devcontainer
9-
image: datajoint/datajoint-python-devcontainer:${PY_VER:-3.11}-${DISTRO:-bookworm}
106
build:
11-
context: .
7+
context: ..
128
dockerfile: .devcontainer/Dockerfile
139
args:
1410
- PY_VER=${PY_VER:-3.11}
1511
- DISTRO=${DISTRO:-bookworm}
16-
17-
volumes:
18-
# Update this to wherever you want VS Code to mount the folder of your project
19-
- ..:/workspaces:cached
20-
21-
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
22-
# cap_add:
23-
# - SYS_PTRACE
24-
# security_opt:
25-
# - seccomp:unconfined
26-
2712
user: root
28-
29-
# Overrides default command so things don't shut down after the process ends.
13+
# Keep container running for devcontainer
3014
command: /bin/sh -c "while sleep 1000; do :; done"

docker-compose.yaml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# Development environment with MySQL and MinIO services
2-
# To run tests: pytest --cov-report term-missing --cov=datajoint tests
2+
# Start services: docker-compose up -d db minio
3+
# Run tests: pixi run test
34
services:
45
db:
56
image: datajoint/mysql:${MYSQL_VER:-8.0}
67
environment:
78
- MYSQL_ROOT_PASSWORD=${DJ_PASS:-password}
89
command: mysqld --default-authentication-plugin=mysql_native_password
9-
# ports:
10-
# - "3306:3306"
11-
# volumes:
12-
# - ./mysql/data:/var/lib/mysql
10+
ports:
11+
- "3306:3306"
1312
healthcheck:
1413
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
1514
timeout: 30s
@@ -20,18 +19,15 @@ services:
2019
environment:
2120
- MINIO_ACCESS_KEY=datajoint
2221
- MINIO_SECRET_KEY=datajoint
23-
# ports:
24-
# - "9000:9000"
25-
# volumes:
26-
# - ./minio/config:/root/.minio
27-
# - ./minio/data:/data
22+
ports:
23+
- "9000:9000"
2824
command: server --address ":9000" /data
2925
healthcheck:
3026
test:
3127
- "CMD"
3228
- "curl"
3329
- "--fail"
34-
- "http://minio:9000/minio/health/live"
30+
- "http://localhost:9000/minio/health/live"
3531
timeout: 30s
3632
retries: 5
3733
interval: 15s

pyproject.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ test = [
8686
"pytest",
8787
"pytest-cov",
8888
"pytest-env",
89-
"docker",
9089
"requests",
9190
"graphviz"
9291
]
@@ -154,16 +153,19 @@ skip = ".git,*.pdf,*.svg,*.csv,*.ipynb,*.drawio"
154153
ignore-words-list = "rever,numer,astroid"
155154

156155
[tool.pytest_env]
157-
# Default values - pytest fixtures will override with actual container details
156+
# Default environment variables for tests
157+
# When running from host: DJ_HOST=localhost (set via pixi task)
158+
# When running in devcontainer/docker: DJ_HOST=db (docker-compose service name)
159+
DJ_HOST="db"
160+
DJ_PORT="3306"
158161
DJ_USER="root"
159162
DJ_PASS="password"
160163
DJ_TEST_USER="datajoint"
161164
DJ_TEST_PASSWORD="datajoint"
165+
S3_ENDPOINT="minio:9000"
162166
S3_ACCESS_KEY="datajoint"
163167
S3_SECRET_KEY="datajoint"
164168
S3_BUCKET="datajoint.test"
165-
PYTHON_USER="dja"
166-
JUPYTER_PASSWORD="datajoint"
167169

168170

169171
[tool.pixi.workspace]
@@ -179,6 +181,12 @@ dev = { features = ["dev"], solve-group = "default" }
179181
test = { features = ["test"], solve-group = "default" }
180182

181183
[tool.pixi.tasks]
184+
# Start required services (MySQL and MinIO)
185+
services-up = "docker-compose up -d db minio"
186+
services-down = "docker-compose down"
187+
# Run tests (requires services to be running)
188+
test = { cmd = "pytest tests/", depends-on = ["services-up"], env = { DJ_HOST = "localhost", DJ_PORT = "3306", S3_ENDPOINT = "localhost:9000" } }
189+
test-cov = { cmd = "pytest --cov-report term-missing --cov=datajoint tests/", depends-on = ["services-up"], env = { DJ_HOST = "localhost", DJ_PORT = "3306", S3_ENDPOINT = "localhost:9000" } }
182190

183191
[tool.pixi.dependencies]
184192
python = ">=3.10,<3.14"

0 commit comments

Comments
 (0)