django-testcontainers-plus 0.1.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.
- django_testcontainers_plus-0.1.0/.gitignore +10 -0
- django_testcontainers_plus-0.1.0/.python-version +1 -0
- django_testcontainers_plus-0.1.0/LICENSE +21 -0
- django_testcontainers_plus-0.1.0/PKG-INFO +312 -0
- django_testcontainers_plus-0.1.0/README.md +267 -0
- django_testcontainers_plus-0.1.0/pyproject.toml +85 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/__init__.py +16 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/manager.py +125 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/providers/__init__.py +21 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/providers/base.py +70 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/providers/mysql.py +87 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/providers/postgres.py +87 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/providers/redis.py +89 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/py.typed +0 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/pytest_plugin.py +104 -0
- django_testcontainers_plus-0.1.0/src/django_testcontainers_plus/runner.py +96 -0
- django_testcontainers_plus-0.1.0/uv.lock +1166 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Andrew Woodward
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-testcontainers-plus
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A plug-and-play testcontainers integration for Django - supports databases, Redis, MinIO, and more
|
|
5
|
+
Project-URL: Homepage, https://github.com/arwoodward/django-testcontainers-plus
|
|
6
|
+
Project-URL: Repository, https://github.com/arwoodward/django-testcontainers-plus
|
|
7
|
+
Project-URL: Documentation, https://github.com/arwoodward/django-testcontainers-plus#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/arwoodward/django-testcontainers-plus/issues
|
|
9
|
+
Author-email: Andrew Woodward <arwoodward553@gmail.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: containers,django,docker,mysql,postgres,redis,testcontainers,testing
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Framework :: Django
|
|
15
|
+
Classifier: Framework :: Django :: 4.2
|
|
16
|
+
Classifier: Framework :: Django :: 5.0
|
|
17
|
+
Classifier: Framework :: Django :: 5.1
|
|
18
|
+
Classifier: Framework :: Pytest
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Topic :: Software Development :: Testing
|
|
29
|
+
Requires-Python: >=3.10
|
|
30
|
+
Requires-Dist: django>=4.2
|
|
31
|
+
Requires-Dist: testcontainers>=4.0.0
|
|
32
|
+
Provides-Extra: all
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: django-stubs>=4.2.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: mypy>=1.8.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-django>=4.5.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
40
|
+
Provides-Extra: mongodb
|
|
41
|
+
Provides-Extra: mysql
|
|
42
|
+
Provides-Extra: postgres
|
|
43
|
+
Provides-Extra: redis
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# Django Testcontainers Plus
|
|
47
|
+
|
|
48
|
+
A plug-and-play testcontainers integration for Django
|
|
49
|
+
|
|
50
|
+
[](https://badge.fury.io/py/django-testcontainers-plus)
|
|
51
|
+
[](https://opensource.org/licenses/MIT)
|
|
52
|
+
|
|
53
|
+
## Why Django Testcontainers Plus?
|
|
54
|
+
|
|
55
|
+
Testing Django applications often requires external services like PostgreSQL, Redis, or S3. Django Testcontainers Plus makes this effortless by:
|
|
56
|
+
|
|
57
|
+
- **Zero Configuration**: Automatically detects your database and service needs from Django settings
|
|
58
|
+
- **Plug and Play**: Install, add to settings, and go - no manual container management
|
|
59
|
+
- **Database Agnostic**: Supports PostgreSQL, MySQL, MariaDB, MongoDB, and more
|
|
60
|
+
- **Beyond Databases**: Redis for caching, MinIO for S3, and other services
|
|
61
|
+
- **Dual Compatibility**: Works with both Django's test runner and pytest
|
|
62
|
+
- **Smart Defaults**: Sensible defaults with full customization when needed
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Using uv (recommended)
|
|
68
|
+
uv add django-testcontainers-plus
|
|
69
|
+
|
|
70
|
+
# Using pip
|
|
71
|
+
pip install django-testcontainers-plus
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Quick Start
|
|
75
|
+
|
|
76
|
+
### Option 1: Django Test Runner (Minimal Setup)
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# settings.py
|
|
80
|
+
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
|
|
81
|
+
|
|
82
|
+
DATABASES = {
|
|
83
|
+
'default': {
|
|
84
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
85
|
+
'NAME': 'myapp',
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
That's it! Run your tests:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python manage.py test
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
PostgreSQL will automatically start in a container, run your tests, and clean up.
|
|
97
|
+
|
|
98
|
+
### Option 2: pytest-django
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
# conftest.py
|
|
102
|
+
pytest_plugins = ['django_testcontainers_plus.pytest_plugin']
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
# settings.py
|
|
107
|
+
DATABASES = {
|
|
108
|
+
'default': {
|
|
109
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
110
|
+
'NAME': 'test',
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Run your tests:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
pytest
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Supported Services
|
|
122
|
+
|
|
123
|
+
### Databases
|
|
124
|
+
- PostgreSQL - Auto-detected from `django.db.backends.postgresql`
|
|
125
|
+
- MySQL/MariaDB - Auto-detected from `django.db.backends.mysql`
|
|
126
|
+
- MongoDB - Coming soon
|
|
127
|
+
- SQL Server - Coming soon
|
|
128
|
+
|
|
129
|
+
### Other Services
|
|
130
|
+
- Redis - Auto-detected from cache/Celery settings
|
|
131
|
+
- MinIO - S3-compatible storage (coming soon)
|
|
132
|
+
- Mailhog - Email testing (coming soon)
|
|
133
|
+
- Elasticsearch - Search (coming soon)
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
### Zero Configuration (Auto-Detection)
|
|
138
|
+
|
|
139
|
+
Django Testcontainers Plus automatically detects services from your settings:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
# PostgreSQL auto-detected
|
|
143
|
+
DATABASES = {
|
|
144
|
+
'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'test'}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Redis auto-detected
|
|
148
|
+
CACHES = {
|
|
149
|
+
'default': {'BACKEND': 'django.core.cache.backends.redis.RedisCache'}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# Celery Redis auto-detected
|
|
153
|
+
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Custom Configuration
|
|
157
|
+
|
|
158
|
+
Override defaults when needed:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
TESTCONTAINERS = {
|
|
162
|
+
'postgres': {
|
|
163
|
+
'image': 'postgres:16-alpine',
|
|
164
|
+
'username': 'testuser',
|
|
165
|
+
'password': 'testpass',
|
|
166
|
+
'dbname': 'testdb',
|
|
167
|
+
},
|
|
168
|
+
'redis': {
|
|
169
|
+
'image': 'redis:7-alpine',
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Disable Auto-Detection
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
TESTCONTAINERS = {
|
|
178
|
+
'postgres': {
|
|
179
|
+
'auto': False, # Disable auto-detection
|
|
180
|
+
'enabled': True, # But explicitly enable it
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Examples
|
|
186
|
+
|
|
187
|
+
### PostgreSQL with Django Test Runner
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
# settings.py
|
|
191
|
+
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
|
|
192
|
+
|
|
193
|
+
DATABASES = {
|
|
194
|
+
'default': {
|
|
195
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
196
|
+
'NAME': 'myapp',
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# Optional: Customize PostgreSQL version
|
|
201
|
+
TESTCONTAINERS = {
|
|
202
|
+
'postgres': {
|
|
203
|
+
'image': 'postgres:15',
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
python manage.py test
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### MySQL with pytest
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
# conftest.py
|
|
216
|
+
pytest_plugins = ['django_testcontainers_plus.pytest_plugin']
|
|
217
|
+
|
|
218
|
+
# settings.py
|
|
219
|
+
DATABASES = {
|
|
220
|
+
'default': {
|
|
221
|
+
'ENGINE': 'django.db.backends.mysql',
|
|
222
|
+
'NAME': 'test',
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
pytest
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### PostgreSQL + Redis
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
# settings.py
|
|
235
|
+
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
|
|
236
|
+
|
|
237
|
+
DATABASES = {
|
|
238
|
+
'default': {
|
|
239
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
240
|
+
'NAME': 'test',
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
CACHES = {
|
|
245
|
+
'default': {
|
|
246
|
+
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
|
247
|
+
'LOCATION': 'redis://localhost:6379/0',
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Both PostgreSQL and Redis containers will start automatically!
|
|
253
|
+
|
|
254
|
+
## How It Works
|
|
255
|
+
|
|
256
|
+
1. **Detection**: Scans your Django settings for database engines and service backends
|
|
257
|
+
2. **Configuration**: Merges detected needs with any custom `TESTCONTAINERS` config
|
|
258
|
+
3. **Startup**: Starts necessary containers before tests run
|
|
259
|
+
4. **Injection**: Updates Django settings with container connection details
|
|
260
|
+
5. **Cleanup**: Stops and removes containers after tests complete
|
|
261
|
+
|
|
262
|
+
## Development
|
|
263
|
+
|
|
264
|
+
This project uses [uv](https://github.com/astral-sh/uv) for package management.
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Clone the repository
|
|
268
|
+
git clone https://github.com/arwoodward/django-testcontainers-plus
|
|
269
|
+
cd django-testcontainers-plus
|
|
270
|
+
|
|
271
|
+
# Install dependencies
|
|
272
|
+
uv sync --dev
|
|
273
|
+
|
|
274
|
+
# Run tests
|
|
275
|
+
uv run pytest
|
|
276
|
+
|
|
277
|
+
# Run linting
|
|
278
|
+
uv run ruff check .
|
|
279
|
+
|
|
280
|
+
# Run type checking
|
|
281
|
+
uv run mypy src/
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Roadmap
|
|
285
|
+
|
|
286
|
+
- [x] PostgreSQL support
|
|
287
|
+
- [x] MySQL/MariaDB support
|
|
288
|
+
- [x] Redis support
|
|
289
|
+
- [x] Django test runner integration
|
|
290
|
+
- [x] pytest plugin
|
|
291
|
+
- [ ] MongoDB support
|
|
292
|
+
- [ ] MinIO (S3) support
|
|
293
|
+
- [ ] Mailhog support
|
|
294
|
+
- [ ] Elasticsearch support
|
|
295
|
+
- [ ] RabbitMQ support
|
|
296
|
+
- [ ] Container reuse between test runs
|
|
297
|
+
- [ ] Parallel test support
|
|
298
|
+
- [ ] Full documentation site
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
307
|
+
|
|
308
|
+
## Credits
|
|
309
|
+
|
|
310
|
+
Inspired by [django-rdtwt](https://github.com/wonkybream/django-rdtwt) but with broader service support and active maintenance.
|
|
311
|
+
|
|
312
|
+
Built with [testcontainers-python](https://github.com/testcontainers/testcontainers-python).
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Django Testcontainers Plus
|
|
2
|
+
|
|
3
|
+
A plug-and-play testcontainers integration for Django
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/py/django-testcontainers-plus)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Why Django Testcontainers Plus?
|
|
9
|
+
|
|
10
|
+
Testing Django applications often requires external services like PostgreSQL, Redis, or S3. Django Testcontainers Plus makes this effortless by:
|
|
11
|
+
|
|
12
|
+
- **Zero Configuration**: Automatically detects your database and service needs from Django settings
|
|
13
|
+
- **Plug and Play**: Install, add to settings, and go - no manual container management
|
|
14
|
+
- **Database Agnostic**: Supports PostgreSQL, MySQL, MariaDB, MongoDB, and more
|
|
15
|
+
- **Beyond Databases**: Redis for caching, MinIO for S3, and other services
|
|
16
|
+
- **Dual Compatibility**: Works with both Django's test runner and pytest
|
|
17
|
+
- **Smart Defaults**: Sensible defaults with full customization when needed
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Using uv (recommended)
|
|
23
|
+
uv add django-testcontainers-plus
|
|
24
|
+
|
|
25
|
+
# Using pip
|
|
26
|
+
pip install django-testcontainers-plus
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### Option 1: Django Test Runner (Minimal Setup)
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
# settings.py
|
|
35
|
+
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
|
|
36
|
+
|
|
37
|
+
DATABASES = {
|
|
38
|
+
'default': {
|
|
39
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
40
|
+
'NAME': 'myapp',
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
That's it! Run your tests:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python manage.py test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
PostgreSQL will automatically start in a container, run your tests, and clean up.
|
|
52
|
+
|
|
53
|
+
### Option 2: pytest-django
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# conftest.py
|
|
57
|
+
pytest_plugins = ['django_testcontainers_plus.pytest_plugin']
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
# settings.py
|
|
62
|
+
DATABASES = {
|
|
63
|
+
'default': {
|
|
64
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
65
|
+
'NAME': 'test',
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Run your tests:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pytest
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Supported Services
|
|
77
|
+
|
|
78
|
+
### Databases
|
|
79
|
+
- PostgreSQL - Auto-detected from `django.db.backends.postgresql`
|
|
80
|
+
- MySQL/MariaDB - Auto-detected from `django.db.backends.mysql`
|
|
81
|
+
- MongoDB - Coming soon
|
|
82
|
+
- SQL Server - Coming soon
|
|
83
|
+
|
|
84
|
+
### Other Services
|
|
85
|
+
- Redis - Auto-detected from cache/Celery settings
|
|
86
|
+
- MinIO - S3-compatible storage (coming soon)
|
|
87
|
+
- Mailhog - Email testing (coming soon)
|
|
88
|
+
- Elasticsearch - Search (coming soon)
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
### Zero Configuration (Auto-Detection)
|
|
93
|
+
|
|
94
|
+
Django Testcontainers Plus automatically detects services from your settings:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# PostgreSQL auto-detected
|
|
98
|
+
DATABASES = {
|
|
99
|
+
'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'test'}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Redis auto-detected
|
|
103
|
+
CACHES = {
|
|
104
|
+
'default': {'BACKEND': 'django.core.cache.backends.redis.RedisCache'}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# Celery Redis auto-detected
|
|
108
|
+
CELERY_BROKER_URL = 'redis://localhost:6379/0'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Custom Configuration
|
|
112
|
+
|
|
113
|
+
Override defaults when needed:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
TESTCONTAINERS = {
|
|
117
|
+
'postgres': {
|
|
118
|
+
'image': 'postgres:16-alpine',
|
|
119
|
+
'username': 'testuser',
|
|
120
|
+
'password': 'testpass',
|
|
121
|
+
'dbname': 'testdb',
|
|
122
|
+
},
|
|
123
|
+
'redis': {
|
|
124
|
+
'image': 'redis:7-alpine',
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Disable Auto-Detection
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
TESTCONTAINERS = {
|
|
133
|
+
'postgres': {
|
|
134
|
+
'auto': False, # Disable auto-detection
|
|
135
|
+
'enabled': True, # But explicitly enable it
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Examples
|
|
141
|
+
|
|
142
|
+
### PostgreSQL with Django Test Runner
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# settings.py
|
|
146
|
+
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
|
|
147
|
+
|
|
148
|
+
DATABASES = {
|
|
149
|
+
'default': {
|
|
150
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
151
|
+
'NAME': 'myapp',
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Optional: Customize PostgreSQL version
|
|
156
|
+
TESTCONTAINERS = {
|
|
157
|
+
'postgres': {
|
|
158
|
+
'image': 'postgres:15',
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
python manage.py test
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### MySQL with pytest
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
# conftest.py
|
|
171
|
+
pytest_plugins = ['django_testcontainers_plus.pytest_plugin']
|
|
172
|
+
|
|
173
|
+
# settings.py
|
|
174
|
+
DATABASES = {
|
|
175
|
+
'default': {
|
|
176
|
+
'ENGINE': 'django.db.backends.mysql',
|
|
177
|
+
'NAME': 'test',
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
pytest
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### PostgreSQL + Redis
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
# settings.py
|
|
190
|
+
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
|
|
191
|
+
|
|
192
|
+
DATABASES = {
|
|
193
|
+
'default': {
|
|
194
|
+
'ENGINE': 'django.db.backends.postgresql',
|
|
195
|
+
'NAME': 'test',
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
CACHES = {
|
|
200
|
+
'default': {
|
|
201
|
+
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
|
202
|
+
'LOCATION': 'redis://localhost:6379/0',
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Both PostgreSQL and Redis containers will start automatically!
|
|
208
|
+
|
|
209
|
+
## How It Works
|
|
210
|
+
|
|
211
|
+
1. **Detection**: Scans your Django settings for database engines and service backends
|
|
212
|
+
2. **Configuration**: Merges detected needs with any custom `TESTCONTAINERS` config
|
|
213
|
+
3. **Startup**: Starts necessary containers before tests run
|
|
214
|
+
4. **Injection**: Updates Django settings with container connection details
|
|
215
|
+
5. **Cleanup**: Stops and removes containers after tests complete
|
|
216
|
+
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
This project uses [uv](https://github.com/astral-sh/uv) for package management.
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Clone the repository
|
|
223
|
+
git clone https://github.com/arwoodward/django-testcontainers-plus
|
|
224
|
+
cd django-testcontainers-plus
|
|
225
|
+
|
|
226
|
+
# Install dependencies
|
|
227
|
+
uv sync --dev
|
|
228
|
+
|
|
229
|
+
# Run tests
|
|
230
|
+
uv run pytest
|
|
231
|
+
|
|
232
|
+
# Run linting
|
|
233
|
+
uv run ruff check .
|
|
234
|
+
|
|
235
|
+
# Run type checking
|
|
236
|
+
uv run mypy src/
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Roadmap
|
|
240
|
+
|
|
241
|
+
- [x] PostgreSQL support
|
|
242
|
+
- [x] MySQL/MariaDB support
|
|
243
|
+
- [x] Redis support
|
|
244
|
+
- [x] Django test runner integration
|
|
245
|
+
- [x] pytest plugin
|
|
246
|
+
- [ ] MongoDB support
|
|
247
|
+
- [ ] MinIO (S3) support
|
|
248
|
+
- [ ] Mailhog support
|
|
249
|
+
- [ ] Elasticsearch support
|
|
250
|
+
- [ ] RabbitMQ support
|
|
251
|
+
- [ ] Container reuse between test runs
|
|
252
|
+
- [ ] Parallel test support
|
|
253
|
+
- [ ] Full documentation site
|
|
254
|
+
|
|
255
|
+
## Contributing
|
|
256
|
+
|
|
257
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
262
|
+
|
|
263
|
+
## Credits
|
|
264
|
+
|
|
265
|
+
Inspired by [django-rdtwt](https://github.com/wonkybream/django-rdtwt) but with broader service support and active maintenance.
|
|
266
|
+
|
|
267
|
+
Built with [testcontainers-python](https://github.com/testcontainers/testcontainers-python).
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "django-testcontainers-plus"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A plug-and-play testcontainers integration for Django - supports databases, Redis, MinIO, and more"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = { text = "MIT" }
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Andrew Woodward", email = "arwoodward553@gmail.com" }
|
|
9
|
+
]
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
keywords = ["django", "testcontainers", "testing", "docker", "containers", "postgres", "mysql", "redis"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Framework :: Django",
|
|
15
|
+
"Framework :: Django :: 4.2",
|
|
16
|
+
"Framework :: Django :: 5.0",
|
|
17
|
+
"Framework :: Django :: 5.1",
|
|
18
|
+
"Framework :: Pytest",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Software Development :: Testing",
|
|
28
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"django>=4.2",
|
|
32
|
+
"testcontainers>=4.0.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=8.0.0",
|
|
38
|
+
"pytest-django>=4.5.0",
|
|
39
|
+
"pytest-cov>=4.1.0",
|
|
40
|
+
"ruff>=0.8.0",
|
|
41
|
+
"mypy>=1.8.0",
|
|
42
|
+
"django-stubs>=4.2.0",
|
|
43
|
+
]
|
|
44
|
+
postgres = []
|
|
45
|
+
mysql = []
|
|
46
|
+
redis = []
|
|
47
|
+
mongodb = []
|
|
48
|
+
all = []
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://github.com/arwoodward/django-testcontainers-plus"
|
|
52
|
+
Repository = "https://github.com/arwoodward/django-testcontainers-plus"
|
|
53
|
+
Documentation = "https://github.com/arwoodward/django-testcontainers-plus#readme"
|
|
54
|
+
Issues = "https://github.com/arwoodward/django-testcontainers-plus/issues"
|
|
55
|
+
|
|
56
|
+
[build-system]
|
|
57
|
+
requires = ["hatchling"]
|
|
58
|
+
build-backend = "hatchling.build"
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 100
|
|
62
|
+
target-version = "py310"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = ["E", "F", "I", "N", "W", "UP", "B", "C4", "PT"]
|
|
66
|
+
ignore = []
|
|
67
|
+
|
|
68
|
+
[tool.mypy]
|
|
69
|
+
python_version = "3.10"
|
|
70
|
+
warn_return_any = true
|
|
71
|
+
warn_unused_configs = true
|
|
72
|
+
disallow_untyped_defs = true
|
|
73
|
+
plugins = ["mypy_django_plugin.main"]
|
|
74
|
+
|
|
75
|
+
[tool.django-stubs]
|
|
76
|
+
django_settings_module = "tests.settings"
|
|
77
|
+
|
|
78
|
+
[tool.pytest.ini_options]
|
|
79
|
+
DJANGO_SETTINGS_MODULE = "tests.settings"
|
|
80
|
+
python_files = ["test_*.py", "*_test.py"]
|
|
81
|
+
addopts = [
|
|
82
|
+
"--cov=django_testcontainers_plus",
|
|
83
|
+
"--cov-report=term-missing",
|
|
84
|
+
"--cov-report=html",
|
|
85
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Django Testcontainers Plus - Plug-and-play testcontainers for Django."""
|
|
2
|
+
|
|
3
|
+
from .manager import ContainerManager
|
|
4
|
+
from .providers import ContainerProvider, MySQLProvider, PostgresProvider, RedisProvider
|
|
5
|
+
from .runner import TestcontainersRunner
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"ContainerManager",
|
|
11
|
+
"ContainerProvider",
|
|
12
|
+
"PostgresProvider",
|
|
13
|
+
"MySQLProvider",
|
|
14
|
+
"RedisProvider",
|
|
15
|
+
"TestcontainersRunner",
|
|
16
|
+
]
|