admin管理员组文章数量:1390519
I want to mock same object with different values but it's not working. I am using unittest mock and pytest
import unittest
from azure.cosmos.exceptions import CosmosResourceExistsError
import pytest
from unittest.mock import patch
@patch('azure.cosmos.CosmosClient', autospec=True)
@pytest.mark.run(order=1)
def test_usage_already_exists(custom_mock_cosmo, mock_sts_session, mock_dynamodb, mock_activation_trns_map):
print(custom_mock_cosmo)
mock_container = mock_cosmo_container(custom_mock_cosmo)
mock_container.read_item.return_value = {"some": "data"}
mock_container.upsert_item.return_value = {"some": "data"}
mock_container.create_item.side_effect = CosmosResourceExistsError(409, "Resource already exists")
# Add debug statement to verify the mock is in place
print(mock_container.create_item)
with pytest.raises(CosmosResourceExistsError):
handle(member, "INSERT", meta_data)
@patch('azure.cosmos.CosmosClient',autospec=True)
@pytest.mark.run(order=2)
def test_your_function1(custom_mock_cosmo,mock_sts_session, mock_dynamodb,mock_activation_trns_map):
print(custom_mock_cosmo)
mock_cosmo_container(custom_mock_cosmo).read_item.return_value = {"some": "data"}
mock_cosmo_container(custom_mock_cosmo).upsert_item.return_value = {"some": "data"}
handle(member, "INSERT", meta_data)
@patch('azure.cosmos.CosmosClient',autospec=True)
@pytest.mark.run(order=3)
def test_your_function(custom_mock_cosmo,mock_sts_session, mock_dynamodb,mock_activation_trns_map):
print(custom_mock_cosmo)
mock_cosmo_container(custom_mock_cosmo).read_item.return_value = {"some": "data"}
mock_cosmo_container(custom_mock_cosmo).upsert_item.return_value = {"some": "data"}
handle(member, "REMOVE", meta_data)
for all the cases i am getting exception i stuck with this please provide some inputs ?
本文标签: pythonPytest mock same object with different return valuesStack Overflow
版权声明:本文标题:python - Pytest mock same object with different return values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744607204a2615428.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论