Skip to content

test: implement per-test isolation for integration tests#343

Merged
nycomp merged 1 commit intoweeklyfrom
feature/test-per-test-isolation
Feb 3, 2026
Merged

test: implement per-test isolation for integration tests#343
nycomp merged 1 commit intoweeklyfrom
feature/test-per-test-isolation

Conversation

@nycomp
Copy link
Contributor

@nycomp nycomp commented Feb 3, 2026

Summary

Implements Option A variant (per-test reset) for issue #335, providing true test isolation while maintaining acceptable performance.

Changes

  • tests/fixtures/services.py: Added ServiceManager.reset_test_data() method

    • Resets storage (SQLite in-memory DB, memory collections) between tests
    • Re-initializes auth/yapper services after reset
    • Preserves Flask apps for performance
  • tests/integration/api/test_assignments.py:

    • Moved reset from tearDownClass() to tearDown()
    • Re-create test tokens in setUp() (required because reset clears credentials)
    • Removed test_00_* prefix from test_list_assignments_empty

Test Results

  • All 12 integration tests pass (up from 6 failures before)
  • Full integration test suite passes (18 tests)
  • No test_00_* prefixes remaining in codebase

Performance Impact

Minimal: ~0.04s increase for 12-test suite (0.25s → 0.29s)

  • reset_test_storage() is cheap (closes/reopens SQLite connection, clears dict)
  • Flask apps are preserved (only storage is reset)

Usage Pattern for Other Tests

def setUp(self):
    self.client = self.app.test_client()
    self.app_context = self.app.app_context().push()
    # Re-create token since tearDown() clears credentials
    self.token = create_test_token(self.user_id)
    self.auth_headers = get_bearer_auth_headers(self.token)

def tearDown(self):
    self.app_context.pop()
    if hasattr(self, 'service_manager'):
        self.service_manager.reset_test_data()

Trade-offs

Pro Con
True test isolation - no test ordering issues Tests using bearer tokens must re-create tokens in setUp()
Removes test_00_* naming hack Slightly slower (but negligible impact)
Cleaner, more maintainable tests

Fixes #335

🤖 Generated with Claude Code

Adds ServiceManager.reset_test_data() method for per-test isolation,
resolving the test_00_* naming hack required for tests that expect
empty state.

Changes:
- Add ServiceManager.reset_test_data() to reset storage between tests
- Move reset from tearDownClass() to tearDown() in test_assignments.py
- Re-create test tokens in setUp() after storage reset
- Remove test_00_* prefix from test_list_assignments_empty

Performance impact: Negligible (~0.04s increase for 12-test suite)
- SQLite in-memory reset: just closes/reopens connection
- MemoryCollection reset: just clears dict
- Flask apps preserved (avoids blueprint re-registration issues)

Fixes #335

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nycomp nycomp linked an issue Feb 3, 2026 that may be closed by this pull request
@nycomp
Copy link
Contributor Author

nycomp commented Feb 3, 2026

Fix #335

@nycomp nycomp merged commit 978bdbb into weekly Feb 3, 2026
4 checks passed
@nycomp nycomp deleted the feature/test-per-test-isolation branch February 3, 2026 06:40
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 Isolation: Fresh DB per test vs shared database

2 participants