-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_annotations.py
More file actions
39 lines (26 loc) · 949 Bytes
/
test_annotations.py
File metadata and controls
39 lines (26 loc) · 949 Bytes
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
"""Show debugger error on annotated test fixtures and pydantic models on python 3.14.
- create python 3.14 venv
- pip install -r requirement.txt
- debug tests with pytest in vscode test explorer
"""
import pytest
from pydantic import BaseModel
# Note that fixture without annotations won't raise exception
@pytest.fixture
def simple_fixture():
return 42
# Raises exception
@pytest.fixture
def annotated_fixture(simple_fixture: int) -> str:
return f"This is an annotated fixture with value {simple_fixture}"
# Raises exception
class AnnotatedTest(BaseModel):
"""A test class with annotated attributes."""
name: str
value: int
# Raises exception
def test_annotated() -> None:
assert 1 + 1 == 2
def test_user_uncaught_exception() -> None:
# Without "User Uncaught Exceptions" checked, debugger won't stop on this genuine exception
raise ValueError("This is a test exception in an annotated test function.")