|
17 | 17 | from .haberdasher_pb2 import Hat, Size |
18 | 18 |
|
19 | 19 |
|
20 | | -@pytest.mark.asyncio |
21 | | -async def test_lifespan() -> None: |
22 | | - class CountingHaberdasher(Haberdasher): |
23 | | - def __init__(self, counter: Counter) -> None: |
24 | | - self._counter = counter |
| 20 | +class CountingHaberdasher(Haberdasher): |
| 21 | + def __init__(self, counter: Counter) -> None: |
| 22 | + self._counter = counter |
| 23 | + |
| 24 | + async def make_hat(self, request, ctx): |
| 25 | + self._counter["requests"] += 1 |
| 26 | + return Hat(size=request.inches, color="blue") |
25 | 27 |
|
26 | | - async def make_hat(self, request, ctx): |
27 | | - self._counter["requests"] += 1 |
28 | | - return Hat(size=request.inches, color="blue") |
29 | 28 |
|
| 29 | +@pytest.mark.asyncio |
| 30 | +async def test_lifespan() -> None: |
30 | 31 | final_count = None |
31 | 32 |
|
32 | 33 | async def counting_haberdasher(): |
@@ -69,14 +70,6 @@ async def counting_haberdasher(): |
69 | 70 |
|
70 | 71 | @pytest.mark.asyncio |
71 | 72 | async def test_lifespan_startup_error() -> None: |
72 | | - class CountingHaberdasher(Haberdasher): |
73 | | - def __init__(self, counter: Counter) -> None: |
74 | | - self._counter = counter |
75 | | - |
76 | | - async def make_hat(self, request, ctx): |
77 | | - self._counter["requests"] += 1 |
78 | | - return Hat(size=request.inches, color="blue") |
79 | | - |
80 | 73 | final_count = None |
81 | 74 |
|
82 | 75 | async def counting_haberdasher(): |
@@ -112,14 +105,6 @@ async def counting_haberdasher(): |
112 | 105 |
|
113 | 106 | @pytest.mark.asyncio |
114 | 107 | async def test_lifespan_shutdown_error() -> None: |
115 | | - class CountingHaberdasher(Haberdasher): |
116 | | - def __init__(self, counter: Counter) -> None: |
117 | | - self._counter = counter |
118 | | - |
119 | | - async def make_hat(self, request, ctx): |
120 | | - self._counter["requests"] += 1 |
121 | | - return Hat(size=request.inches, color="blue") |
122 | | - |
123 | 108 | async def counting_haberdasher(): |
124 | 109 | counter = Counter() |
125 | 110 | try: |
@@ -167,14 +152,6 @@ async def counting_haberdasher(): |
167 | 152 |
|
168 | 153 | @pytest.mark.asyncio |
169 | 154 | async def test_lifespan_not_supported() -> None: |
170 | | - class CountingHaberdasher(Haberdasher): |
171 | | - def __init__(self, counter: Counter) -> None: |
172 | | - self._counter = counter |
173 | | - |
174 | | - async def make_hat(self, request, ctx): |
175 | | - self._counter["requests"] += 1 |
176 | | - return Hat(size=request.inches, color="blue") |
177 | | - |
178 | 155 | final_count = None |
179 | 156 |
|
180 | 157 | async def counting_haberdasher(): |
|
0 commit comments