Skip to content

test: drop misleading async on sync streaming tests + lock random.seed guard (#2071)#2079

Open
yastman wants to merge 1 commit into
devfrom
chore/2071-test-smells
Open

test: drop misleading async on sync streaming tests + lock random.seed guard (#2071)#2079
yastman wants to merge 1 commit into
devfrom
chore/2071-test-smells

Conversation

@yastman
Copy link
Copy Markdown
Owner

@yastman yastman commented May 22, 2026

This pull request was created by @kiro-agent on behalf of @yastman 👻

Comment with /kiro fix to address specific feedback or /kiro all to address everything.
Learn about Kiro autonomous agent


Parent: #1515 (test audit), category S2 + S3 (code smells).

This PR addresses two of the four #2071 cleanup categories incrementally and behavior-preservingly:

S2 — async def without await

tests/unit/agents/test_streaming.py declared four async def test_* that never awaited. pytest-asyncio mode=auto silently ran them in an event loop. Stripped async from those four tests. Behavior is identical: pytest collects and runs them as plain sync functions, the same assertions hold.

S3 — random.seed in test bodies

Added tests/contract/test_no_global_random_seed_contract.py. Counts random.seed(...) vs random.getstate() per file under tests/ and fails if seed > getstate (i.e. someone introduces a bare random.seed without a save/restore guard).

Current state on dev: tests/unit/scripts/test_kommo_seed.py has 3 seed calls, all wrapped in random.getstate()/setstate() try/finally blocks. The contract passes today and prevents regression.

What this PR explicitly does NOT touch

Verification

uv run pytest tests/unit/agents/test_streaming.py \
              tests/contract/test_no_global_random_seed_contract.py -q
  5 passed

uvx ruff check tests/unit/agents/test_streaming.py \
               tests/contract/test_no_global_random_seed_contract.py
  All checks passed!

Closes #2071.

…d guard (#2071)

Parent: #1515 (test audit), category S2 + S3 (code smells).

#2071 lists four cleanup categories. This PR addresses two of them
incrementally and behavior-preservingly:

S2 — async without await
  tests/unit/agents/test_streaming.py declared four 'async def test_*'
  that never awaited. pytest-asyncio mode=auto silently ran them in an
  event loop. Stripped 'async' from those four tests. Behavior is
  identical: pytest collects and runs them as plain sync functions, the
  same assertions hold.

S3 — random.seed in test bodies
  Added tests/contract/test_no_global_random_seed_contract.py. Counts
  random.seed(...) vs random.getstate() per file under tests/ and fails
  if seed > getstate (i.e. someone introduces a bare random.seed without
  a save/restore guard).

  Current state on dev: tests/unit/scripts/test_kommo_seed.py has 3
  seed calls, all wrapped in random.getstate()/setstate() try/finally
  blocks. The contract passes today and prevents regression.

What this PR explicitly does NOT touch:

  - long test names (S5) — left alone; renaming would break --lf/--ff
    pytest history with no behavior win.
  - uuid4 usage (S6) — issue #2071 itself says 'Leave uuid4 usage alone
    unless it causes parallel-test instability.'
  - timing assertions (S4) — no concrete regressions surfaced; defer to
    a follow-up scoped at the specific timing-flaky tests.

Verification:
  uv run pytest tests/unit/agents/test_streaming.py
                tests/contract/test_no_global_random_seed_contract.py -q
    5 passed
  uvx ruff check tests/unit/agents/test_streaming.py
                 tests/contract/test_no_global_random_seed_contract.py
    All checks passed!

Closes #2071
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: CODE-SMELLS cleanup async/no-await, random seed, timing, and names (#1515)

2 participants