Skip to content

Commit 896e6cd

Browse files
Merge pull request #1269 from d-v-b/feat/pytest-container-management
use pytest to manage docker container startup for tests
2 parents 9fcb25a + b3f82d9 commit 896e6cd

File tree

10 files changed

+3087
-15
lines changed

10 files changed

+3087
-15
lines changed

.codespellrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
skip = .git,*.pdf,*.svg,*.csv,*.ipynb,*.drawio
33
# Rever -- nobody knows
44
# numer -- numerator variable
5-
ignore-words-list = rever,numer
5+
ignore-words-list = rever,numer,astroid

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SCM syntax highlighting & preventing 3-way merges
2+
pixi.lock merge=binary linguist-language=YAML linguist-generated=true

.github/workflows/test.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ jobs:
3434
python-version: ${{matrix.py_ver}}
3535
- name: Integration test
3636
env:
37-
PY_VER: ${{matrix.py_ver}}
3837
MYSQL_VER: ${{matrix.mysql_ver}}
39-
# taking default variables set in docker-compose.yaml to sync with local test
4038
run: |
41-
export HOST_UID=$(id -u)
42-
docker compose --profile test up --quiet-pull --build --exit-code-from djtest djtest
39+
pip install -e ".[test]"
40+
pytest --cov-report term-missing --cov=datajoint tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,5 @@ cython_debug/
185185
dj_local_conf.json
186186
*.env
187187
!.vscode/launch.json
188+
# pixi environments
189+
.pixi

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# HOST_UID=$(id -u) PY_VER=3.11 DJ_VERSION=$(grep -oP '\d+\.\d+\.\d+' datajoint/version.py) docker compose --profile test up --build --exit-code-from djtest djtest
1+
# Development environment with MySQL and MinIO services
2+
# To run tests: pytest --cov-report term-missing --cov=datajoint tests
23
services:
34
db:
45
image: datajoint/mysql:${MYSQL_VER:-8.0}

pixi.lock

Lines changed: 2712 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ Repository = "https://github.com/datajoint/datajoint-python"
7878
dj = "datajoint.cli:cli"
7979
datajoint = "datajoint.cli:cli"
8080

81-
[project.optional-dependencies]
81+
[dependency-groups]
8282
test = [
8383
"pytest",
8484
"pytest-cov",
85+
"pytest-env",
86+
"docker",
87+
"requests",
88+
"graphviz"
8589
]
90+
91+
[project.optional-dependencies]
8692
dev = [
8793
"pre-commit",
8894
"black==24.2.0",
@@ -103,3 +109,33 @@ package-dir = {"" = "src"}
103109

104110
[tool.setuptools.dynamic]
105111
version = { attr = "datajoint.version.__version__"}
112+
113+
[tool.pytest_env]
114+
# Default values - pytest fixtures will override with actual container details
115+
DJ_USER="root"
116+
DJ_PASS="password"
117+
DJ_TEST_USER="datajoint"
118+
DJ_TEST_PASSWORD="datajoint"
119+
S3_ACCESS_KEY="datajoint"
120+
S3_SECRET_KEY="datajoint"
121+
S3_BUCKET="datajoint.test"
122+
PYTHON_USER="dja"
123+
JUPYTER_PASSWORD="datajoint"
124+
125+
126+
[tool.pixi.workspace]
127+
channels = ["conda-forge"]
128+
platforms = ["linux-64"]
129+
130+
[tool.pixi.pypi-dependencies]
131+
datajoint = { path = ".", editable = true }
132+
133+
[tool.pixi.environments]
134+
default = { solve-group = "default" }
135+
dev = { features = ["dev"], solve-group = "default" }
136+
test = { features = ["test"], solve-group = "default" }
137+
138+
[tool.pixi.tasks]
139+
140+
[tool.pixi.dependencies]
141+
graphviz = ">=13.1.2,<14"

src/datajoint/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def __setitem__(self, key, value):
278278
"database.host",
279279
"database.user",
280280
"database.password",
281+
"database.port",
281282
"external.aws_access_key_id",
282283
"external.aws_secret_access_key",
283284
"loglevel",
@@ -288,6 +289,7 @@ def __setitem__(self, key, value):
288289
"DJ_HOST",
289290
"DJ_USER",
290291
"DJ_PASS",
292+
"DJ_PORT",
291293
"DJ_AWS_ACCESS_KEY_ID",
292294
"DJ_AWS_SECRET_ACCESS_KEY",
293295
"DJ_LOG_LEVEL",
@@ -296,6 +298,14 @@ def __setitem__(self, key, value):
296298
)
297299
if v is not None
298300
}
301+
302+
# Convert DJ_PORT from string to int if present
303+
if "database.port" in mapping and mapping["database.port"] is not None:
304+
try:
305+
mapping["database.port"] = int(mapping["database.port"])
306+
except ValueError:
307+
logger.warning(f"Invalid DJ_PORT value: {mapping['database.port']}, using default port 3306")
308+
del mapping["database.port"]
299309
if mapping:
300310
logger.info(f"Overloaded settings {tuple(mapping)} from environment variables.")
301311
config.update(mapping)

0 commit comments

Comments
 (0)