Skip to content

Tight Coupling: Tests Accessing Private Attributes #125

@coderabbitai

Description

@coderabbitai

Overview

This is a sub-task of #119 - Refactor: Address Law of Demeter violations for better encapsulation

Priority: Medium
Pattern: Test code directly accessing _private attributes of classes under test

Violations Found

80+ instances found across test files, including:

  • transport._initialized (multiple test files)
  • transport._sys.stdin.readline (test_transport.py)
  • transport._lock (test_stdio.py)
  • executor._semaphore (test_executor.py)
  • safety_filter._sanitize_string_argument() (test_safety.py)

Why It's a Problem

  1. Tests are coupled to implementation details
  2. Violates encapsulation
  3. Makes code harder to maintain
  4. Reduces test value

Refactoring Strategies

Test through public API only, or add test helper methods if absolutely necessary.

Acceptance Criteria

  • Audit all test files for private attribute access
  • Categorize violations by necessity
  • Refactor tests to use public API where possible
  • Add test helper methods only where truly necessary
  • Document testing patterns in contributor guide
  • All tests pass after refactoring

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions