|
1 | 1 | import importlib |
2 | | -from typing import AsyncIterable |
| 2 | +from typing import AsyncIterable, Literal |
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 | from pytest_snapshot.plugin import Snapshot |
|
8 | 8 | from tests.codegen.snapshot.codegen_snapshot_fixtures import validate_codegen |
9 | 9 | from tests.common_handlers import basic_stream |
10 | 10 |
|
| 11 | +_AlreadyGenerated = False |
11 | 12 |
|
12 | | -@pytest.mark.parametrize("handlers", [{**basic_stream}]) |
13 | | -async def test_basic_stream(snapshot: Snapshot, client: Client) -> None: |
14 | | - validate_codegen( |
15 | | - snapshot=snapshot, |
16 | | - read_schema=lambda: open("tests/codegen/stream/schema.json"), |
17 | | - target_path="test_basic_stream", |
18 | | - client_name="StreamClient", |
19 | | - ) |
| 13 | + |
| 14 | +@pytest.fixture |
| 15 | +def stream_client_codegen(snapshot: Snapshot) -> Literal[True]: |
| 16 | + global _AlreadyGenerated |
| 17 | + if not _AlreadyGenerated: |
| 18 | + validate_codegen( |
| 19 | + snapshot=snapshot, |
| 20 | + read_schema=lambda: open("tests/codegen/stream/schema.json"), |
| 21 | + target_path="test_basic_stream", |
| 22 | + client_name="StreamClient", |
| 23 | + ) |
| 24 | + _AlreadyGenerated = True |
20 | 25 |
|
21 | 26 | import tests.codegen.snapshot.snapshots.test_basic_stream |
22 | 27 |
|
23 | 28 | importlib.reload(tests.codegen.snapshot.snapshots.test_basic_stream) |
| 29 | + return True |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize("handlers", [{**basic_stream}]) |
| 33 | +async def test_basic_stream( |
| 34 | + stream_client_codegen: Literal[True], |
| 35 | + client: Client, |
| 36 | +) -> None: |
24 | 37 | from tests.codegen.snapshot.snapshots.test_basic_stream import ( |
25 | 38 | StreamClient, # noqa: E501 |
26 | 39 | ) |
|
0 commit comments