Skip to content

Commit 9955fe4

Browse files
AbhiPrasadclaude
andauthored
test(logger): remove redundant tests and parametrize duplicates in test_logger.py (#830)
## Summary Cleans up `py/src/braintrust/test_logger.py` by removing redundant and near-empty tests and parametrizing near-duplicates. Test-only change; no SDK code is modified. - **4,999 → 3,436 lines**, **223 → 189 tests** in `test_logger.py` (one test moved to `test_gitutil.py`). - Each commit is one self-contained batch and can be reviewed on its own. ### What changed - **Removed no-op or duplicated tests**, for example: - `init` dataset-id tests that never called `init()` - `JSONAttachment` tests that only checked objects they had just built - `span.log` binary/bad-key tests that asserted only that a key exists - attachment, deep-copy, `id_gen` and `span_components` tests already covered in `test_bt_json.py`, `test_id_gen.py` or `test_span_components.py` - **Parametrized near-duplicates:** - generator `MAX_GENERATOR_ITEMS` limits (sync/async × 3/0/-1) - span export format (9 tests → 1) - `model_dump` metadata across 7 logging APIs - masking across logger, experiment, child span and dataset: one shared masking function replaces 4 hand-written ones - prompt/parameters version-over-environment - strict-mode templates - bt-eval BTQL merge - `atexit`, `proxy_conn` - `emit_log` `str.format`/t-string template rendering - **Dissolved the `TestLogger` grab-bag** into plain pytest functions. - **Replaced manual `os.environ` save/restore** (and a hand-built `pytest.MonkeyPatch()`) with the `monkeypatch` fixture. - **Moved** `test_get_repo_info_without_settings_returns_none` to `test_gitutil.py`. ### Assertions that got stricter - Generator limit 0 now also checks that no truncation warning is logged. The old tests missed a regression there. - The inferred child-span name is now checked exactly (`user_fn:user_module.py:2`) by calling `start_span()` from a module that isn't under `braintrust.*`. Before, the test only checked that the name wasn't empty. - The experiment span-link test checks the full URL instead of three substrings. - Template-rendering cases check the full metadata, the log level, and that no `error` field is set. - The masking test checks that no unmasked value appears anywhere in the logged rows. - New case: `BRAINTRUST_OTEL_COMPAT` takes priority over `BRAINTRUST_LEGACY_IDS` for the export format. ## Test plan - [x] `nox -s test_core`: 926 passed, 69 skipped, 12 xfailed (main: 955 passed). Outside `test_logger.py`, the only difference is the test moved into `test_gitutil.py`. - [x] `test_logger.py` passes in 5 shuffled orders, and on Python 3.11 (t-string cases skip) as well as 3.14. - [x] Mutation checks: for each rewritten area (generator limits, export selection, masking, version precedence, BTQL merge, template rendering, inferred span names), I broke the code under test in `logger.py` and confirmed the new tests fail. - [x] `ruff`, `pre-commit` hooks, `pylint --errors-only`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e41959e commit 9955fe4

2 files changed

Lines changed: 778 additions & 2336 deletions

File tree

‎py/src/braintrust/test_gitutil.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ def test_repo_info_returns_none_when_git_cannot_be_resolved(monkeypatch: pytest.
6363
assert gitutil._current_repo() is None
6464
assert gitutil.repo_info() is None
6565
assert list(gitutil.get_past_n_ancestors()) == []
66+
67+
68+
def test_get_repo_info_without_settings_returns_none():
69+
"""Direct call to get_repo_info with settings=None should return None."""
70+
assert gitutil.get_repo_info(None) is None

0 commit comments

Comments
 (0)