Skip to content

test(logging): port logging tests to pytest style#153

Closed
tmgbedu wants to merge 1 commit into
mainfrom
task/logging-tests-pytest-716
Closed

test(logging): port logging tests to pytest style#153
tmgbedu wants to merge 1 commit into
mainfrom
task/logging-tests-pytest-716

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Repurposes the idea behind PR #81 (cleaner pytest-style logging tests) while starting from the strong, mutation-verified suite added in #147 (commit 9d2d968).

What changed

Rewrote fastapi_startkit/tests/logging/test_logging.py from unittest.TestCase into pytest style:

  • class Test* groups with plain assert statements
  • fixtures replace setUp/tearDown and setUpModule/tearDownModule (module-scoped autouse boot fixture, per-class isolation fixtures for root-logger handlers and timezone)
  • capsys replaces manual redirect_stdout
  • section banners for readability

Rigor preserved (from #147)

  • No circular Slack assertion: the Slack test pins the concrete endpoint https://slack.com/api/chat.postMessage, never driver.slack_url (the value that produced the call).
  • Timezone-aware daily file test: proves the on-disk file name follows the configured timezone by inspecting real files at a UTC day boundary (UTC+14 vs UTC-10), not by comparing self-built strings.
  • All other assertions (level filtering, broadcast, factory lookups, provider wiring, listener, make_directory, config defaults) carried over unchanged.

Weaknesses intentionally NOT reintroduced

  • The tautological test_daily_channel_different_date_produces_new_file (compared two self-built string literals, never exercised channel behavior).
  • The Slack circular self-reference assertion.

Verification

  • pytest tests/logging/test_logging.py → 52 passed
  • Full suite → 1650 passed, 7 skipped; total coverage 71.18% (≥ 68% threshold)
  • Logging module coverage: 85%

Rewrite the logging test suite from unittest.TestCase into pytest-style
test classes with plain assert statements, fixtures, and section banners.

All rigorous, mutation-verified assertions are preserved: the Slack test
pins the concrete chat.postMessage endpoint rather than driver.slack_url
(which would be circular), and the daily-file test proves the on-disk file
name follows the configured timezone by inspecting real files.

The two weak tests are intentionally not carried over: the tautological
daily 'different date' test that compared two self-built string literals,
and the Slack circular self-reference assertion.
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tmgbedu

tmgbedu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Code review verdict: REQUEST CHANGES (do not merge yet)

Substantive review passed — faithful pytest port:

  • ✅ No assertion strength lost: 52 test methods in both this PR and prior Add logging module tests and raise coverage threshold to 68% #147; assertions carried 1:1 (assertIs→is, assertRaises→pytest.raises, redirect_stdout→capsys).
  • ✅ Tautological test_daily_channel_different_date_produces_new_file NOT reintroduced — daily test inspects real on-disk files at a UTC day boundary (UTC+14 vs UTC-10).
  • ✅ Slack circular self-reference NOT reintroduced — assert url == "https://slack.com/api/chat.postMessage", never driver.slack_url.
  • ✅ Pytest + codecov/patch green; logging coverage preserved (test-only change).

Blocker — CI Ruff job is red (ruff format --check . fails):
tests/logging/test_logging.py, TestMultiBaseChannel.test_broadcasts_each_level_to_all_channels (~line 224): the expected level list is packed multiple-items-per-line with a trailing comma, so ruff 0.15.12 (same version as CI) expands it one-item-per-line via the magic-trailing-comma rule. Fix: uv run ruff format tests/logging/test_logging.py, commit, and push. Once Ruff is green this is an approve.

@tmgbedu

tmgbedu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #157. Both PRs port the logging tests from unittest to pytest and are functionally identical (52 tests, same assertions, #147 rigor preserved — no tautological daily test, Slack test pins the concrete endpoint). #157 is kept because it is already green (this PR had a red ruff-format CI), is cleaner (~113 fewer lines with a shared isolated_named_root fixture), and was confirmed equivalent in a direct diff comparison. Please use #157 instead.

@tmgbedu tmgbedu closed this Jul 10, 2026
@tmgbedu

tmgbedu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #157. Both PRs port the logging tests from unittest to pytest with identical test coverage (52 tests, same assertions, #147 rigor preserved), but #157 is already green on CI and slightly cleaner (shared isolated_named_root fixture, ~113 fewer lines). Keeping #157 as the single logging-tests PR. Thanks!

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.

1 participant