Skip to content

Commit e7a6822

Browse files
Refactor plugin tests (#2273)
* refactor existing tests frmo unittest style setup and teardown to pytest fixtures (adds pytest-mock as a dep to use mocker.patch) * Common fixture for temp directory, move everything into flat pytest fixtures * mypy * changes.md
1 parent 21c3780 commit e7a6822

9 files changed

Lines changed: 892 additions & 1029 deletions

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- Declare workflow-level `permissions: contents: read` on the 8 remaining workflows (CVE-2025-30066 hardening) `PR #2241`
1010
- Skip base class tests in test runs `PR #2263`
11-
- Transitioned from unittest.Testcase to pytest fixtures `PR #2265`
11+
- Transitioned from unittest.Testcase to pytest fixtures (`PR #2265`, `PR #2273`)
1212
- Replace MinIO Docker container with moto in-memory mock for S3 tests `PR #2272`
1313

1414
## Documentation
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from collections import defaultdict
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
import bandersnatch.storage
7+
8+
9+
@pytest.fixture(autouse=True)
10+
def plugin_test_dir(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
11+
"""
12+
Automatically isolates each test into its own temp dir and
13+
ensures the storage plugin registry is clean.
14+
"""
15+
monkeypatch.setattr(
16+
bandersnatch.storage,
17+
"loaded_storage_plugins",
18+
defaultdict(list),
19+
)
20+
monkeypatch.chdir(tmp_path)
21+
return tmp_path

0 commit comments

Comments
 (0)