How to combine multiple RequestMock contexts (pytest fixture)?
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず RequestsMock のコンテキストと登録動作を確認し、次に関連する issue #542 と、ここに示されている pytest のフィクスチャを確認してください。test_api と test_api2 を再現してください。example.foo と example.bar へのリクエストの両方が、片方の mock がもう片方を上書きすることなく、登録された 200 レスポンスを返せば完了です。
索引モデルが issue の本文から書いたものです。
説明
How can I combine multiple RequestsMock contexts so that they don't overwrite each other?
In my specific case I'm using RequestsMock as pytest fixtures.
If there isn't a supported way to do this, what's the easiest way to programmatically copy the registered mocks from 2 different RequestsMock into a 3rd one?
from typing import Generator
import pytest
import requests
import responses
@pytest.fixture
def mock_foo_api() -> Generator[responses.RequestsMock, None, None]:
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
"https://example.foo",
status=200,
body="{'msg': 'foo'}"
content_type="application/json",
)
yield rsps
@pytest.fixture
def mock_bar_api() -> Generator[responses.RequestsMock, None, None]:
with responses.RequestsMock() as rsps:
rsps.add(
responses.GET,
"https://example.bar",
status=200,
body="{'msg': 'bar'}"
content_type="application/json",
)
yield rsps
def test_api(mock_foo_api: responses.RequestsMock, mock_bar_api: responses.RequestsMock):
# this test fails
bar_req = requests.get("https://example.bar")
assert bar_req.status_code == 200
foo_req = requests.get("https://example.foo")
assert foo_req.status_code == 200
# can I do something like this?? 👇
@pytest.fixture
def hypothetical_combined_api_mocks(
mock_foo_api: responses.RequestsMock,
mock_bar_api: responses.RequestsMock
):
with responses.RequestsMock() as rsps:
for registered_mock in [*mock_foo_api.<SOMETHING>, *mock_bar_api.<SOMETHING>]
rsps.add(registered_mock)
yield rsps
def test_api2(hypothetical_combined_api_mocks: responses.RequestsMock):
bar_req = requests.get("https://example.bar")
assert bar_req.status_code == 200
foo_req = requests.get("https://example.foo")
assert foo_req.status_code == 200
- This seems somewhat related to #https://github.com/getsentry/responses/issues/542
- 主要言語
- Python
- スター
- 4.3k
- フォーク
- 389
- 平均マージ
- 1日 17時間
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
getsentry/responses のほかの issue
-
json_params_matcher fails on falsy top-level JSON primitives (0, False, "")対応中かも @mayureshsonawane17 が 30 日前に担当しました。 オープンWaiting for: Product Owner
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 3 日以内に返信
-
enhancement Waiting for: Product Owner
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
getsentry/responses#783 · コメント 1 件 · リアクション 3 件 ·
メンテナーはふだん 3 日以内に返信
-
bug Waiting for: Product Owner
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
getsentry/responses#780 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
enhancement question
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
メンテナーはふだん 3 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
getsentry/responses#765 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
getsentry/responses の issue をすべて見る
似ている issue
-
area:cli bug difficulty:1
難易度 1/5 1〜3時間 初心者へのやさしさ 87/100
MakazhanAlpamys/Soup#2491 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/onnxscript#3155 ·
メンテナーはふだん 4 日以内に返信
-
IFEval nth-paragraph checker reads the wrong paragraph when a blank separator is present対応中かも @chetana1410 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
EleutherAI/lm-evaluation-harness#4530 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
sv_SE vat_id() has 14 digits: the "16" organisation number prefix is kept対応中かも @kevin9327 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 19 日以内に返信