Skip to content

Commit fbfc31d

Browse files
authored
Expose --recreate flag to ddev env test (DataDog#22521)
* Expose --recreate flag to `ddev env test` * Add changelog and ingore-state handling * Add AGENTS.md instructions for recreating testing environments * Prefer `--recreate` in AGENT.md docs
1 parent 95c3c7f commit fbfc31d

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

AGENTS.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## General Development Guidelines
44

5-
* Auto-format code with `ddev test -fs`.
5+
- Auto-format code with `ddev test -fs`.
66

77
## Python Type Hinting
88

@@ -52,16 +52,19 @@ Run unit and integration tests with `ddev --no-interactive test <INTEGRATION>`.
5252
Run E2E tests by following these steps:
5353

5454
1. List available environments for the integration:
55+
5556
```shell
5657
ddev env show <INTEGRATION>
5758
```
5859

5960
2. Start a specific environment:
61+
6062
```shell
6163
ddev env start --dev <INTEGRATION> <ENV>
6264
```
6365

6466
3. Run the E2E tests in that environment:
67+
6568
```shell
6669
ddev env test --dev <INTEGRATION> <ENV>
6770
```
@@ -82,6 +85,20 @@ ddev env stop pgbouncer py3.11-1.23
8285

8386
Run specific tests with `ddev --no-interactive test <INTEGRATION> -- -k <PYTEST_FILTER_STRING>`, for example `ddev --no-interactive test kuma -- -k test_code_class_injection -s`.
8487

88+
### Recreating Environments
89+
90+
Add `--recreate` to recreate test environments from scratch:
91+
92+
```shell
93+
# Unit/integration tests - recreates Hatch environments
94+
ddev test --recreate <INTEGRATION>
95+
96+
# E2E tests - recreates both Hatch environments and Docker containers/volumes
97+
ddev env test --dev --recreate <INTEGRATION> <ENV>
98+
```
99+
100+
For E2E tests, `--recreate` performs `docker compose down --volumes` followed by `docker compose up -d --force-recreate`.
101+
85102
## Code Formatting
86103

87104
Format code with `ddev test -fs <INTEGRATION>`. For example, for the pgbouncer integration, run `ddev test -fs pgbouncer`.
@@ -96,9 +113,9 @@ Changelog files are named `<PR_NUMBER>.<TYPE>` and placed in the integration's `
96113

97114
### Version Bumping Behavior
98115

99-
* `fixed` - Bug fixes. Bumps the **patch** version (e.g., 1.0.0 → 1.0.1)
100-
* `added` - New features. Bumps the **minor** version (e.g., 1.0.0 → 1.1.0)
101-
* `changed` - Breaking changes or significant modifications. Bumps the **major** version (e.g., 1.0.0 → 2.0.0)
116+
- `fixed` - Bug fixes. Bumps the **patch** version (e.g., 1.0.0 → 1.0.1)
117+
- `added` - New features. Bumps the **minor** version (e.g., 1.0.0 → 1.1.0)
118+
- `changed` - Breaking changes or significant modifications. Bumps the **major** version (e.g., 1.0.0 → 2.0.0)
102119

103120
### Command Format
104121

ddev/changelog.d/22521.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add --recreate/-r flag to ddev env test command to recreate environments from scratch before running tests

ddev/src/ddev/cli/env/test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
multiple=True,
4040
help='Environment variables to pass to the Agent e.g. -e DD_URL=app.datadoghq.com -e DD_API_KEY=foobar',
4141
)
42+
@click.option('--recreate', '-r', is_flag=True, help='Recreate environments from scratch')
4243
@click.option('--junit', is_flag=True, hidden=True)
4344
@click.option('--python-filter', envvar='PYTHON_FILTER', hidden=True)
4445
@click.option('--new-env', is_flag=True, hidden=True)
@@ -53,6 +54,7 @@ def test_command(
5354
local_base: bool,
5455
agent_build: str | None,
5556
extra_env_vars: tuple[str, ...],
57+
recreate: bool,
5658
junit: bool,
5759
python_filter: str | None,
5860
new_env: bool,
@@ -121,6 +123,11 @@ def test_command(
121123
active = set(active_envs)
122124
for env_name in env_names:
123125
env_active = env_name in active
126+
127+
# If recreating and environment is already active, stop it first to get a fresh environment
128+
if recreate and env_active:
129+
ctx.invoke(stop, intg_name=intg_name, environment=env_name, ignore_state=False)
130+
124131
ctx.invoke(
125132
start,
126133
intg_name=intg_name,
@@ -130,7 +137,7 @@ def test_command(
130137
agent_build=agent_build,
131138
extra_env_vars=extra_env_vars,
132139
hide_help=True,
133-
ignore_state=env_active,
140+
ignore_state=env_active and not recreate,
134141
)
135142

136143
env_data = storage.get(integration.name, env_name)
@@ -147,6 +154,7 @@ def test_command(
147154
test,
148155
target_spec=f'{intg_name}:{env_name}',
149156
pytest_args=pytest_args,
157+
recreate=recreate,
150158
junit=junit,
151159
hide_header=True,
152160
e2e=True,

0 commit comments

Comments
 (0)