Skip to content

Commit 7c698a5

Browse files
committed
refactor: conftest: Make display_recipient_factory a fixture.
This commit adds the pytest fixture decorator to display_recipient_ factory() function, allowing it to be reused separately throughout the codebase.
1 parent 2d1f08b commit 7c698a5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tests/conftest.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,21 @@ def unicode_emojis():
208208
])
209209

210210

211-
def display_recipient_factory(recipient_id: Optional[int]=None,
212-
recipient_name: str=""):
211+
@pytest.fixture
212+
def display_recipient_factory():
213213
"""
214214
Generate display_recipient field for (stream/PM/group) messages
215215
FIXME: Refactor other tests to make this depend only on recipient_id.
216216
"""
217-
return {
218-
'id': recipient_id,
219-
'is_mirror_dummy': False,
220-
'full_name': recipient_name,
221-
'short_name': f'{recipient_id}',
222-
'email': f'user-{recipient_id}@zulip.com',
223-
} if recipient_id else "PTEST"
217+
def _factory(recipient_id: Optional[int]=None, recipient_name: str=""):
218+
return {
219+
'id': recipient_id,
220+
'is_mirror_dummy': False,
221+
'full_name': recipient_name,
222+
'short_name': f'{recipient_id}',
223+
'email': f'user-{recipient_id}@zulip.com',
224+
} if recipient_id else "PTEST"
225+
return _factory
224226

225227

226228
@pytest.fixture
@@ -256,15 +258,15 @@ def _factory(msg_id: int, msg_type: str, stream_id: Optional[int],
256258

257259

258260
@pytest.fixture
259-
def stream_msg_template(msg_template_factory):
261+
def stream_msg_template(display_recipient_factory, msg_template_factory):
260262
recipient = display_recipient_factory()
261263
msg_template = msg_template_factory(
262264
537286, 'stream', 205, 1520918722, recipient)
263265
return msg_template
264266

265267

266268
@pytest.fixture
267-
def pm_template(msg_template_factory):
269+
def pm_template(display_recipient_factory, msg_template_factory):
268270
recipients = [display_recipient_factory(_id, name) for _id, name in
269271
{(5179, 'Boo Boo'), (5140, 'Foo Foo')}]
270272
msg_template = msg_template_factory(
@@ -273,7 +275,7 @@ def pm_template(msg_template_factory):
273275

274276

275277
@pytest.fixture
276-
def group_pm_template(msg_template_factory):
278+
def group_pm_template(display_recipient_factory, msg_template_factory):
277279
recipients = [display_recipient_factory(_id, name) for _id, name in
278280
{(5179, 'Boo Boo'), (5140, 'Foo Foo'), (5180, 'Bar Bar')}]
279281
msg_template = msg_template_factory(

0 commit comments

Comments
 (0)