Moto secretsmanager mock一次不能模拟多个机密对象

2024-05-16 20:17:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个方法要测试调用在多个机密对象上获取_secret:

@pytest.fixture(scope="session")
def client():
    conn = boto3.client("secretsmanager", region_name="us-west-1")
    yield conn


@mock_secretsmanager
def test_get_secret_value(client):
   client.create_secret(
       Name="one", SecretString="sdfsdf"
   )
   client.create_secret(
       Name="two", SecretString="werwewe"
   )
   # Function that gets value of 2 secrets- "one" and "two"
   # Only "two" will exist as the second call to create_secret() will override the first it seems
   mymodule.get_one_and_two("one","two")

我得到一个错误:botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetSecretValue operation: Secrets Manager can't find the specified secret

我是不是用错了moto?如何创建我的函数可以访问的两个秘密

编辑

看来这个问题应该已经解决了。我似乎仍然有这个问题:https://github.com/spulec/moto/issues/1893


Tags: andthenameclientgetsecretvaluedef