-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathconftest.py
More file actions
63 lines (44 loc) · 1.68 KB
/
conftest.py
File metadata and controls
63 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
In `conftest.py` we define fixtures that are used in multiple tests. pytest will automatically
inject them into the test functions that need them by signature matching.
"""
from pathlib import Path
import pytest
from flask.testing import FlaskClient
from app import app
from views.challenge import ChallengeManager
CHALLENGES_DIR = Path(__file__).parent.parent / "challenges"
ALL_QUESTIONS = list(CHALLENGES_DIR.glob("**/question.py"))
ALL_SOLUTIONS = list(CHALLENGES_DIR.glob("**/solution*.py"))
@pytest.fixture()
def assets_dir() -> Path:
"""
Path to the test assets directory located alongside this file.
Returns:
Path: Path to the "assets" directory adjacent to this conftest.py file.
"""
return Path(__file__).parent / "assets"
@pytest.fixture()
def mgr(assets_dir: Path):
"""
Create a ChallengeManager for the "challenges" subdirectory of the provided assets directory.
Parameters:
assets_dir (Path): Path to the test assets directory containing challenge data.
Returns:
ChallengeManager: Instance initialized with `assets_dir / "challenges"`.
"""
return ChallengeManager(assets_dir / "challenges")
@pytest.fixture()
def test_client() -> FlaskClient:
"""
Create a Flask test client for the application.
Returns:
test_client (FlaskClient): A test client bound to the application for issuing HTTP requests in tests.
"""
return app.test_client()
@pytest.fixture(params=ALL_QUESTIONS, ids=lambda x: x.parent.name)
def question_file(request):
return request.param
@pytest.fixture(params=ALL_SOLUTIONS, ids=lambda x: x.parent.name)
def solution_file(request):
return request.param