Skip to content

Remove test workaround from production code in borg/list_repo.py:42 #2392

@mr-raj12

Description

@mr-raj12

The problem

Production code at src/vorta/borg/list_repo.py:41-42 contains a test-specific workaround:

if not result['data']:
    result['data'] = {}  # TODO: Workaround for tests. Can't read mock results 2x.

This exists because the borg_json_output test fixture opens file handles that get reused across chained Borg jobs. When jobs chain together (e.g., prune triggers list archives refresh), the second job reads from an exhausted file handle (position at EOF) and gets empty content.

This is problematic because:

  • Production code contains test-specific logic
  • Could silently mask real errors where data is legitimately empty
  • Only fixes BorgListRepoJob, other chained jobs could have the same issue

Requested Solution

Fix the test infrastructure in tests/unit/conftest.py to provide fresh file handles for each mock call, then remove the workaround from production code.

Option 1: Create fresh file handles each time borg_json_output() is called
Option 2: Use StringIO objects pre-loaded with content instead of actual file handles

Alternatives

  • Keep the workaround (not ideal - mixes test and production concerns)
  • Reset file position with seek(0) between calls (harder to implement correctly)

Additional context

Related: PR #2353 improved test mocking for system dependencies but didn't address this file handle reuse issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions