-
Notifications
You must be signed in to change notification settings - Fork 175
Description
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.