46 Commits
Author SHA1 Message Date
f929d68ba6 test: clear the ruff baseline in tests/ so the lint gate reflects the PR under review (#52115)
issue: #52114

Makes `ruff check` and `ruff format --check` pass over all of `tests/`,
so the `Ruff (changed files only)` job stops failing PRs for violations
they did not introduce (most recently #51903, which got 69 errors from
an 8-line change).

Almost all of this is mechanical. The behavioural changes are called out
individually below: one `NameError` fix, three shadowed duplicate
definitions, 13 assertion gaps, and two undefined names that only became
visible once star imports were expanded.

### Layout

Seven reviewable commits:

| commit | what | files |
|---|---|---|
| 1 | `ruff format` | 170 |
| 2 | `ruff check --fix` (safe fixes only, no `--unsafe-fixes`) | 156 |
| 3 | F821 fix + `tests/ruff.toml` | 4 |
| 4 | three shadowed duplicate definitions | 4 |
| 5 | close 13 assertion gaps behind F841 | 7 |
| 6 | expand star imports, re-enable F403/F405/F821 | 33 |
| 7 | enable E402, E712, E722 | 16 |

1745 violations → 0. Only `tests/` is touched.

### The undefined-name bug

`chaos/test_chaos_memory_stress.py`:
`TestMemoryStressReplica.prepare_collection` referenced bare `nb` and
`dim`. Those are class attributes, never module-level names, so the
fixture raised `NameError` the moment it ran — and the line directly
above it already used `self.dim`. Changed to `self.nb` / `self.dim`.
This was the only F821 in `tests/`; **the rule stays enabled**.

### Three shadowed duplicate definitions

Three places define the same name twice in the same scope. Python keeps
the later one, so the earlier definition is dead while still reading as
live code — a test that looks like it exists and never runs.

**`restful_client/testcases/test_vector_operations.py` —
`TestDeleteVector`**

```python
@pytest.mark.L0
class TestDeleteVector(TestBase):          # line 778 — shadowed, never ran
    def test_delete_vector_default(...)    # 2x2 parametrized

@pytest.mark.L1
class TestDeleteVector(TestBase):          # line 838 — wins
    def test_delete_vector_with_invalid_api_key(...)
    def test_delete_vector_with_invalid_collection_name(...)
    def test_delete_vector_with_non_primary_key(...)
```

The second holds only negative cases, and the file already uses
`TestInsertVectorNegative` / `TestSearchVectorNegative`, so this is a
copy whose class name was never updated. Renamed it to
`TestDeleteVectorNegative`.

**This is the one to look at:** it brings back an `L0` case, so 4
parametrizations of `test_delete_vector_default` start running in PR CI.
They have never executed, so if the restful delete path has drifted
since they were written, this is where it surfaces.

**`python_client/testcases/test_compaction.py` —
`test_compact_after_delete`**

Defined twice in `TestCompactionParams`, covering different things: the
shadowed one (L3, `@parametrize("delete_pos", [1, tmp_nb // 2])`) covers
*partial* deletes plus a compaction-plan check; the surviving one (L2)
deletes everything. There is already a separate
`test_compact_after_delete_all`, so partial-delete coverage existed only
in the shadowed case and was not running. Renamed it to
`test_compact_after_delete_partial`; the surviving definition is
untouched.

**`python_client/utils/util_pymilvus.py` — `add_vector_field`**

Defined twice with different signatures:

```python
def add_vector_field(entities, is_normal=False):     # line 455 — shadowed
    ...
    entities.append(field)
    return entities

def add_vector_field(nb, dimension=default_dim):     # line 527 — wins
    field_name = gen_unique_str()
    field = {...}          # built, then discarded
    return field_name      # returns only the name
```

Removed the second — both the broken one and the one that was winning.
Grepped the whole repo: **neither definition has a caller**; every
`add_vector_field` hit is something else
(`test_milvus_client_add_vector_field` test methods, the
`Op.add_vector_field` enum member in `chaos/checker.py`, a `Checker`
method of the same name). Dead-code removal, not an API change.

**Net effect on what executes:** `test_delete_vector_default` ×4
(**L0**) and `test_compact_after_delete_partial` ×2 (L3) start running;
nothing stops running; the 3 negative cases keep running under the new
class name. Computed by parsing each file before and after and resolving
shadowing the way Python does, not by reading the diff.

F811 is now clean across `tests/` with no per-file suppressions.

### Star imports expanded, F403/F405/F821 re-enabled

33 of 307 files used `from utils.util_pymilvus import *` and friends.
Inside those, pyflakes cannot tell a typo from a star-imported name — it
downgrades everything unresolved to F405, and **F821 never fires**. The
`NameError` fixed in commit 3 was only catchable because that file
happens not to use a star import.

The 379 F405 hits were only **58 distinct names**. All are now explicit,
resolved by walking the star modules in source order (later import wins,
matching Python). Names that `util_pymilvus` merely re-exports come from
their real source now — `DataType` from `pymilvus`, `np` from `numpy`,
`log` from `utils.util_log` — rather than being laundered through it.

Turning F821 on immediately caught **two real undefined names**, both in
`rate_limit/test_rate_limit.py` (L3, so it has never run in CI):

```python
for collection_num in range(collectionRateLimit):   # no such name
#                          ^ the parametrize arg is `collection_rate_limit`, and it is
#                            a string ("10"/"500"), so range() needs int().
#                            The same test uses the correct name 30 lines below.

mil.uninstall(release_name, namespace=NAMESPACE)    # no such name
#  ^ MilvusOperator.uninstall has exactly this signature, and other suites do the
#    same under `mic`/`milvus_op` — the instantiation was just missing.
```

Both fixed. `test_milvus_client_data_integrity_new.py` needed 15 `noqa`
markers instead: its `prepare_data` fixture injects those names via
`globals()[field] = ...`, which no static analysis can follow. That
block has other problems — a `float is None` check against the builtin,
an always-true `if "is null" or "IS NULL" in expression`, leftover
`binbin_debug1` logging — but rewriting fixture logic does not belong
here; noted in #52116.

### 13 assertion gaps closed

Of ~80 F841 hits, most are harmless scratch values. 13 were a call whose
result was bound and then never checked. Highlights:

- `test_milvus_client_database.py`: two tests apply a non-existent
property key (`data.replica.number`, note `data.` not `database.`),
describe the database, and drop it without checking anything. Their
docstrings say `actual: run successfully` / `nothing changed` — the
intent was to prove nothing changed. Now asserted.
- `test_milvus_client_alias.py`: two assertions were commented out,
**and they were commented out for a reason** — `list_aliases()[0]`
returns a dict, so `assert alias in aliases` would have tested dict
keys. Rewritten against `[0]["aliases"]` (how the rest of the file does
it) and re-enabled. In the skipped `alias_default` test the calls were
also missing the required `collection_name` argument.

The remaining ~65 F841 stay, and the rule stays off.

### E402, E712, E722 also enabled

**E722** (37 sites): mechanical `except:` → `except Exception:`. Checked
the two ways this could change behaviour, both empty: no bare-except
try-block can raise `SystemExit`/`KeyboardInterrupt`, and **none calls
`pytest.skip`/`fail`/`xfail`**. That second one matters — pytest's
`Skipped` derives from `BaseException`, so a bare except silently eats
it while `except Exception` would not. 0 of 37, so behaviour is
unchanged.

**E402** (5 sites): imports that were just in the wrong place — `import
re` sat 70 lines into `check/param_check.py`, and the two
`resource_group` modules imported `rich` after their module-level
constants. Nothing to do with `sys.path`, which is what an earlier
version of this description wrongly claimed.

**E712** (5 sites), gone through one at a time rather than
bulk-rewritten:

| site | value | change |
|---|---|---|
| `test_milvus_client_partition.py` | `has_partition()` | → `is False` —
stricter than `not result`, which would pass on `None` |
| `test_restart.py` | JSON status flag | → `is True` |
| `test_restart.py` | local `break_flag` | → plain truth test, it is a
real bool |
| `test_query.py` | wrapper `check_result` | → `is True` |
| `test_milvus_client_ttl.py` | `hit.get(bool_field)` | **kept as `==
False` + noqa** |

That last one is the reason this rule cannot be bulk-fixed: `.get()`
returns `None` for a missing field, so `not ...` would pass exactly
where the assertion should fail, and `is False` would break on a numpy
bool.

### What ruff.toml still disables

| rule | n | reason |
|---|---|---|
| F841 | ~65 | tests deliberately keep call results; the 13 that were
genuine assertion gaps are fixed above |
| UP031 | 95 | pure style rewrite that catches no bugs, and 27 sites use
`% (...)` tuples where it is not equivalent |

Everything else pyflakes/pycodestyle checks is on, including `F401`,
`F811` and `F821`, so new code cannot introduce dead, duplicate or
undefined names. Tracked in #52116.

### Verification

Not just "ruff is green" — the mechanical passes were checked for
semantic drift:

- **Format pass:** parsed all 307 files before and after and compared
ASTs with string constants normalized away → **zero structural
differences**. The only AST-visible deltas are 146 string-constant
changes, every one whitespace-only (docstring indentation / trailing
whitespace); zero non-whitespace string changes.
- **Import removals:** 142 imports were dropped. For each, checked
whether the bound name still appears anywhere in its file. 115 have no
remaining reference at all. The 27 that still matched textually were
each read by hand and are all comments (`# pdb.set_trace()`, the
commented-out checker dict in `test_load_with_checker.py`), docstring
prose (`"input random collection name"`, `"Tuple[List[Dict]]"`), string
literals (`"Collection ID"`, the `"config"` dict key), a different
binding (`from time import sleep`), or attribute access through another
module (`ct.CaseLabel`, `np.random`). **No real reference was removed.**
- **Python version:** the pyupgrade rewrites emit `datetime.UTC` (3.11+)
and `X | None` (3.10+). `tests/.python-version` is 3.12,
`tests/scripts/python-env.sh` defaults to 3.12, and
`tests/docker/Dockerfile` is `python:3.12-bullseye`.
- **`compileall`** over all 307 files under Python 3.12 passes.
- No external reference to `TestDeleteVector`,
`test_compact_after_delete`, or `add_vector_field` exists anywhere in
the repo (`*.py`, `*.sh`, `*.yaml`, `*.json`).

### Conflict surface

Of the 100 currently-open PRs, 9 touch `tests/*.py` and only **2**
overlap with this change: #51903 (3 of its 5 files) and #51856 (1 file).
The other 7 touch files that were already format-clean. Worth merging
promptly to keep that number small.

`.pre-commit-config.yaml` needs no change — it already runs with
`--config=tests/ruff.toml`, so local hooks and CI stay in sync.

---------

Signed-off-by: xiaofanluan <[email protected]>
Co-authored-by: xiaofanluan <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
2026-08-03 14:54:18 +08:00
ThreadDao 56693836ae [test] Add load balance verify in querynode scale test (#19028) (#19054)
Signed-off-by: ThreadDao <[email protected]>

Signed-off-by: ThreadDao <[email protected]>

Signed-off-by: ThreadDao <[email protected]>
2022-09-07 19:24:35 +08:00
ThreadDao a7b5dc6e04 [test] Update scale test image pull (#18437)
Signed-off-by: ThreadDao <[email protected]>
2022-07-28 16:00:31 +08:00
ThreadDao 19f2971e11 [test] Upgrade milvus scale test and Change k8s client config (#18404)
Signed-off-by: ThreadDao <[email protected]>
2022-07-26 09:00:33 +08:00
ThreadDao 2c18bed24c [test] Update xfail skip cases and scale test cases (#17929)
Signed-off-by: ThreadDao <[email protected]>

[test] Update xfail skip cases and scale test cases

Signed-off-by: ThreadDao <[email protected]>
2022-06-30 15:54:18 +08:00
Jenny Li 4ac5ebc9f1 [skip e2e]Move milvus-dev to milvus (#17941)
Signed-off-by: Jenny Li <[email protected]>
2022-06-30 15:20:22 +08:00
ThreadDao a0854210b7 [test] Update scale replica case as issue fixed (#17390)
Signed-off-by: ThreadDao <[email protected]>
2022-06-08 17:02:07 +08:00
ThreadDao 8945b80a64 [test][skip-e2e] Add counter decorater and scale query multi replicas test (#16845)
Signed-off-by: ThreadDao <[email protected]>
2022-05-09 14:51:52 +08:00
zhenshan.cao 426f607637 Update version of pymilvus and fix ci cases (#16527)
Signed-off-by: zhenshan.cao <[email protected]>
2022-04-19 15:41:39 +08:00
ThreadDao c6839bc729 [skip e2e] Fix scale test pod is not ready when reading logs (#15981)
Signed-off-by: ThreadDao <[email protected]>
2022-03-10 16:13:59 +08:00
ThreadDao 788ff29443 [skip e2e] Update scale test cases (#15369)
Signed-off-by: ThreadDao <[email protected]>
2022-01-24 19:51:39 +08:00
ThreadDao 9612557fe4 [skip e2e] Update scale test server logs export (#15302)
Signed-off-by: ThreadDao <[email protected]>
2022-01-20 09:11:41 +08:00
ThreadDao 2abc3b3260 [skii e2e] Add scale test pipeline server logs archive (#15234)
Signed-off-by: ThreadDao <[email protected]>
2022-01-18 09:21:36 +08:00
ThreadDao 892763b823 [skip e2e] Update scale test image tag to dynamic (#15040)
Signed-off-by: ThreadDao <[email protected]>
2022-01-13 14:57:33 +08:00
ThreadDao 50695e5b8b [skip e2e] Fix index timeout after scale out (#15185)
Signed-off-by: ThreadDao <[email protected]>
2022-01-13 14:29:34 +08:00
ThreadDao 71ce45a407 [skip e2e] Optimize indexnode scale test case (#15016)
Signed-off-by: ThreadDao <[email protected]>
2022-01-07 19:09:29 +08:00
ThreadDao 0ed65a878f [skip e2e] Enable expand indexnode test release uninstall (#14869)
Signed-off-by: ThreadDao <[email protected]>
2022-01-05 17:49:20 +08:00
ThreadDao bd2e5b6f08 [skip e2e] Update scale index repeated release name (#14829)
Signed-off-by: ThreadDao <[email protected]>
2022-01-05 13:27:35 +08:00
ThreadDao 2dad746a7e [skip e2e] Enable scale test release uninstall (#14773)
Signed-off-by: ThreadDao <[email protected]>
2022-01-04 16:21:22 +08:00
ThreadDao 42517a3fc6 [skip e2e] Remove unused scale constants (#14299)
Signed-off-by: ThreadDao <[email protected]>
2021-12-27 15:26:39 +08:00
ThreadDao 6b57e87acb [skip e2e] Update scale test image tag (#14294)
Signed-off-by: ThreadDao <[email protected]>
2021-12-27 15:22:57 +08:00
ThreadDao 396ccf7bd4 [skip e2e] Update milvus image harbor (#14047)
Signed-off-by: ThreadDao <[email protected]>
2021-12-23 14:36:16 +08:00
ThreadDao 72b4e1f718 [skip e2e] Update milvus image harbor (#13874)
Signed-off-by: ThreadDao <[email protected]>
2021-12-21 16:07:02 +08:00
ThreadDao 312aa23c77 [skip e2e] Delete helm deploy in scale test (#13872)
Signed-off-by: ThreadDao <[email protected]>
2021-12-21 16:05:08 +08:00
ThreadDao 71a226c6e1 [skip e2e] Update scale test README (#13864)
Signed-off-by: ThreadDao <[email protected]>
2021-12-21 15:55:46 +08:00
ThreadDao 4e678d89d8 [skip ci] Add comment to scale queryNode and dataNode test (#13551)
Signed-off-by: ThreadDao <[email protected]>
2021-12-17 08:55:14 +08:00
ThreadDao 853a7a1a60 [skip ci] Update scale proxy test and delete shrink proxy (#13550)
Signed-off-by: ThreadDao <[email protected]>
2021-12-17 08:53:26 +08:00
ThreadDao 600a8aa575 [skip ci] Add case to test proxy scale (#13298)
Signed-off-by: ThreadDao <[email protected]>
2021-12-13 21:29:24 +08:00
ThreadDao 6845d2d90c [skip ci] Add operator in scale shrink indxnode test (#13069)
Signed-off-by: ThreadDao <[email protected]>
2021-12-09 15:27:09 +08:00
ThreadDao ed0e6f72f3 [skip ci] Update datanode replicas in scale test (#12988)
Signed-off-by: ThreadDao <[email protected]>
2021-12-08 17:41:07 +08:00
ThreadDao e3758a05c6 [skip ci] Update scale index node test (#12942)
Signed-off-by: ThreadDao <[email protected]>
2021-12-08 13:22:14 +08:00
ThreadDao 55e62cc7ff [skip ci] Update scale data node test (#12879)
Signed-off-by: ThreadDao <[email protected]>
2021-12-07 15:53:03 +08:00
ThreadDao 3ef67c0404 [skip ci] Update scale query node test (#12729)
Signed-off-by: ThreadDao <[email protected]>
2021-12-03 20:29:51 +08:00
ThreadDao 5d64a2012c [skip ci] Add deploy default mic in scale (#11931)
Signed-off-by: ThreadDao <[email protected]>
2021-11-16 21:25:33 +08:00
ThreadDao 4dcba85bfb [skip ci] Update operator deploy in datanode scale (#11837)
Signed-off-by: ThreadDao <[email protected]>
2021-11-15 20:03:27 +08:00
ThreadDao 7bf00a263c [skip ci] Remove unused import (#11756)
Signed-off-by: ThreadDao <[email protected]>
2021-11-12 19:55:10 +08:00
ThreadDao 638d0ac291 Update scale deploy milvus by operator (#10529)
Signed-off-by: ThreadDao <[email protected]>
2021-10-25 10:51:10 +08:00
ThreadDao 0e6faab245 [skip ci] Add default scale release prefix (#9683)
Signed-off-by: ThreadDao <[email protected]>
2021-10-11 20:18:29 +08:00
ThreadDao 54a4e2cbeb [skip ci] Remove unused import of scale proxy (#8793)
Signed-off-by: ThreadDao <[email protected]>
2021-09-28 19:30:03 +08:00
ThreadDao 2d27258d3c [skip ci] Add comment to scale constants (#8595)
Signed-off-by: ThreadDao <[email protected]>
2021-09-26 17:43:58 +08:00
ThreadDao f8b2a64805 Add annotations to the func of helm_env (#7985)
Signed-off-by: ThreadDao <[email protected]>
2021-09-15 17:37:53 +08:00
ThreadDao c7f96e45c3 Update scale test README (#7872)
Signed-off-by: ThreadDao <[email protected]>
2021-09-14 13:11:54 +08:00
ThreadDao d456f0c677 Delete scale default helm chart path (#7829)
Signed-off-by: ThreadDao <[email protected]>
2021-09-13 19:38:58 +08:00
ThreadDao ecfbcd4760 Fix not exist milvus chart (#7271)
Signed-off-by: ThreadDao <[email protected]>
2021-08-24 19:35:51 +08:00
ThreadDao bd250f28ac Optmize scale helm env (#7263)
Signed-off-by: ThreadDao <[email protected]>
2021-08-24 16:07:52 +08:00
binbin eff75c7701 Replace sdk source and merge tests and tests20 (#7182)
Signed-off-by: Binbin Lv <[email protected]>
2021-08-20 11:00:56 +08:00