Skip to content

Commit 5f343e0

Browse files
committed
conftests (#98106)
`mypy` no errors
1 parent 1335b7c commit 5f343e0

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

tests/conftest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ def _open_files() -> frozenset[str]:
5151

5252

5353
@pytest.fixture(autouse=True)
54-
def unclosed_files():
54+
def unclosed_files() -> Generator[None]:
5555
fds = _open_files()
5656
yield
5757
assert _open_files() == fds
5858

5959

6060
@pytest.fixture(autouse=True)
61-
def unclosed_threads(request):
61+
def unclosed_threads(request: pytest.FixtureRequest) -> Generator[None]:
6262
# TODO(DI-1067): strict mode
6363
yield from thread_leaks.check_test(request, strict=False)
6464

6565

6666
@pytest.fixture(autouse=True)
67-
def validate_silo_mode():
67+
def validate_silo_mode() -> Generator[None]:
6868
# NOTE! Hybrid cloud uses many mechanisms to simulate multiple different configurations of the application
6969
# during tests. It depends upon `override_settings` using the correct contextmanager behaviors and correct
7070
# thread handling in acceptance tests. If you hit one of these, it's possible either that cleanup logic has
@@ -83,23 +83,23 @@ def validate_silo_mode():
8383

8484

8585
@pytest.fixture(autouse=True)
86-
def setup_simulate_on_commit(request):
86+
def setup_simulate_on_commit(request: pytest.FixtureRequest) -> Generator[None]:
8787
from sentry.testutils.hybrid_cloud import simulate_on_commit
8888

8989
with simulate_on_commit(request):
9090
yield
9191

9292

9393
@pytest.fixture(autouse=True)
94-
def setup_enforce_monotonic_transactions(request):
94+
def setup_enforce_monotonic_transactions(request: pytest.FixtureRequest) -> Generator[None]:
9595
from sentry.testutils.hybrid_cloud import enforce_no_cross_transaction_interactions
9696

9797
with enforce_no_cross_transaction_interactions():
9898
yield
9999

100100

101101
@pytest.fixture(autouse=True)
102-
def audit_hybrid_cloud_writes_and_deletes(request):
102+
def audit_hybrid_cloud_writes_and_deletes(request: pytest.FixtureRequest) -> Generator[None]:
103103
"""
104104
Ensure that write operations on hybrid cloud foreign keys are recorded
105105
alongside outboxes or use a context manager to indicate that the
@@ -137,13 +137,13 @@ def audit_hybrid_cloud_writes_and_deletes(request):
137137

138138

139139
@pytest.fixture(autouse=True)
140-
def clear_caches():
140+
def clear_caches() -> Generator[None]:
141141
yield
142142
cache.clear()
143143

144144

145145
@pytest.fixture(autouse=True)
146-
def check_leaked_responses_mocks():
146+
def check_leaked_responses_mocks() -> Generator[None]:
147147
yield
148148
leaked = responses.registered()
149149
if leaked:
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
from uuid import uuid4
22

33
import pytest
4+
from sentry_relay.auth import PublicKey, SecretKey
5+
6+
from sentry.models.relay import Relay
47

58

69
@pytest.fixture
7-
def key_pair():
10+
def key_pair() -> tuple[SecretKey, PublicKey]:
811
from sentry_relay.auth import generate_key_pair
912

1013
return generate_key_pair()
1114

1215

1316
@pytest.fixture
14-
def public_key(key_pair):
17+
def public_key(key_pair: tuple[SecretKey, PublicKey]) -> PublicKey:
1518
return key_pair[1]
1619

1720

1821
@pytest.fixture
19-
def private_key(key_pair):
22+
def private_key(key_pair: tuple[SecretKey, PublicKey]) -> SecretKey:
2023
return key_pair[0]
2124

2225

2326
@pytest.fixture
24-
def relay_id():
27+
def relay_id() -> str:
2528
return str(uuid4())
2629

2730

2831
@pytest.fixture
29-
def relay(relay_id, public_key):
30-
from sentry.models.relay import Relay
31-
32+
def relay(relay_id: str | int, public_key: PublicKey) -> Relay:
3233
return Relay.objects.create(relay_id=relay_id, public_key=str(public_key), is_internal=True)

tests/sentry/feedback/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from openai.types.chat.chat_completion_message import ChatCompletionMessage
77

88

9-
def create_dummy_openai_response(*args, **kwargs) -> ChatCompletion:
9+
def create_dummy_openai_response(*args: object, **kwargs: Any) -> ChatCompletion:
1010
return ChatCompletion(
1111
id="test",
1212
choices=[

tests/sentry/feedback/usecases/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
from collections.abc import Callable, Generator
2+
from typing import Any
13
from unittest import mock
24

35
import pytest
46

57

68
@pytest.fixture
7-
def mock_produce_occurrence_to_kafka():
9+
def mock_produce_occurrence_to_kafka() -> Generator[mock.MagicMock]:
810
with mock.patch(
911
"sentry.feedback.usecases.ingest.create_feedback.produce_occurrence_to_kafka"
1012
) as mck:
1113
yield mck
1214

1315

1416
@pytest.fixture(autouse=True)
15-
def llm_settings(set_sentry_option):
17+
def llm_settings(
18+
set_sentry_option: Callable[[str, dict[str, dict[str, Any]]], Any],
19+
) -> Generator[None]:
1620
with (
1721
set_sentry_option(
1822
"llm.provider.options",

tests/sentry/tasks/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import contextlib
2+
from collections.abc import Callable, Generator
3+
from typing import Any
24
from unittest import mock
35

46
import pytest
57

68

79
@pytest.fixture
8-
def register_plugin(request):
10+
def register_plugin(
11+
request: pytest.FixtureRequest,
12+
) -> Generator[Callable[[dict[str, Any], type[Any]], None]]:
913
from sentry.plugins.base import plugins
1014

11-
def inner(globals, cls):
15+
def inner(globals: dict[str, Any], cls: type[Any]) -> None:
1216
ctx.enter_context(mock.patch.dict(globals, {cls.__name__: cls}))
1317
plugins.register(cls)
1418
request.addfinalizer(lambda: plugins.unregister(cls))

tests/sentry/utils/sdk_crashes/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
from collections.abc import Callable, Collection
2+
from types import ModuleType
3+
14
import pytest
25

6+
from sentry.models.project import Project
7+
from sentry.services.eventstore.models import Event
38
from sentry.utils.sdk_crashes.path_replacer import FixedPathReplacer
49
from sentry.utils.sdk_crashes.sdk_crash_detection_config import (
510
SDKCrashDetectionConfig,
@@ -9,8 +14,10 @@
914

1015

1116
@pytest.fixture
12-
def store_event(default_project, factories):
13-
def inner(data):
17+
def store_event(
18+
default_project: Project, factories: ModuleType
19+
) -> Callable[[dict[str, Collection[str]]], Event]:
20+
def inner(data: dict[str, Collection[str]]) -> Event:
1421
return factories.store_event(data=data, project_id=default_project.id)
1522

1623
return inner

0 commit comments

Comments
 (0)