Skip to content

Commit 68b3dc4

Browse files
committed
Give future test files automatic access to shared fixtures
The static_dir and static fixtures now live in conftest.py, where pytest discovers and injects them into any test file automatically. Helpers like ResponseCollector, make_scope, and receive stay in the test file because they're utilities that tests instantiate directly, not fixtures that pytest injects.
1 parent 750c1f6 commit 68b3dc4

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

tests/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from staticware import StaticFiles
6+
7+
8+
@pytest.fixture()
9+
def static_dir(tmp_path: Path) -> Path:
10+
d = tmp_path / "static"
11+
d.mkdir()
12+
(d / "styles.css").write_text("body { color: red; }")
13+
sub = d / "images"
14+
sub.mkdir()
15+
(sub / "logo.png").write_bytes(b"\x89PNG fake image data")
16+
return d
17+
18+
19+
@pytest.fixture()
20+
def static(static_dir: Path) -> StaticFiles:
21+
return StaticFiles(static_dir)

tests/test_staticware.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,6 @@ def expected_hash(content: bytes, length: int = 8) -> str:
6161
# ── StaticFiles: hashing and url() ──────────────────────────────────────
6262

6363

64-
@pytest.fixture()
65-
def static_dir(tmp_path: Path) -> Path:
66-
d = tmp_path / "static"
67-
d.mkdir()
68-
(d / "styles.css").write_text("body { color: red; }")
69-
sub = d / "images"
70-
sub.mkdir()
71-
(sub / "logo.png").write_bytes(b"\x89PNG fake image data")
72-
return d
73-
74-
75-
@pytest.fixture()
76-
def static(static_dir: Path) -> StaticFiles:
77-
return StaticFiles(static_dir)
78-
7964

8065
def test_file_map_contains_all_files(static: StaticFiles, static_dir: Path) -> None:
8166
assert "styles.css" in static.file_map

0 commit comments

Comments
 (0)