mpfaffenberger / mpfaffenberger/code_puppy

tests/conftest.py mock_cleanup fixture pre-calls the mock, making assert_called_once() a tautology

Open Beginner friendly
#412 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
814
Forks
278
Avg merge
2d 5h
Merged PRs (30d)
76

Description

Problem

tests/conftest.py:126-135 defines a fixture that pre-calls a mock so that assert_called_once() passes regardless of what production code does:

@pytest.fixture
def mock_cleanup():
    """Provide a MagicMock that has been called once to satisfy tests expecting a cleanup call.
    Note: This is a test scaffold only; production code does not rely on this.
    """
    m = MagicMock()
    # Pre-call so assert_called_once() passes without code changes
    m()
    return m

It is consumed by tests/test_auto_save_session.py:150 / :186:

result = cp_config.auto_save_session_if_enabled()
...
mock_cleanup.assert_called_once()   # always true — the fixture called m() itself

This assertion is a tautology. It verifies nothing about auto_save_session_if_enabled() — if the session-cleanup call were deleted from production code tomorrow, the test would still pass. This is worse than no assertion because it gives false confidence ("errors should never pass silently" applies to test failures too).

Suggested fix

Patch the real cleanup function and assert on it:

@patch("code_puppy.config.cleanup_sessions")
def test_auto_save_session_if_enabled_success(self, mock_cleanup, ...):
    ...
    result = cp_config.auto_save_session_if_enabled()
    assert result is True
    mock_cleanup.assert_called_once_with(Path(autosave_dir), max_sessions)

Then delete the mock_cleanup fixture from conftest entirely.

Filed by Zen Reviewer C (code-puppy-60635a)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/conftest.py:126-135 and the two cases in tests/test_auto_save_session.py:150 and :186. Patch code_puppy.config.cleanup_sessions in those tests, run the auto-save session tests, and verify the mock receives Path(autosave_dir) and max_sessions exactly once. Remove the mock_cleanup fixture once the assertions cover the production call.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.