Skip to content

Commit 7f98b0c

Browse files
Only generate the snapshot code once
1 parent 75f3431 commit 7f98b0c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

tests/codegen/stream/test_stream.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import importlib
2-
from typing import AsyncIterable
2+
from typing import AsyncIterable, Literal
33

44
import pytest
55
from pytest_snapshot.plugin import Snapshot
@@ -8,19 +8,32 @@
88
from tests.codegen.snapshot.codegen_snapshot_fixtures import validate_codegen
99
from tests.common_handlers import basic_stream
1010

11+
_AlreadyGenerated = False
1112

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
2025

2126
import tests.codegen.snapshot.snapshots.test_basic_stream
2227

2328
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:
2437
from tests.codegen.snapshot.snapshots.test_basic_stream import (
2538
StreamClient, # noqa: E501
2639
)

0 commit comments

Comments
 (0)