我正在尝试测试一些使用boto的python代码.我宁愿不尝试对AWS进行集成测试,所以我试图用moto来模拟它,而且它的行为并不像我期望的那样.
这是测试代码:
import io
import boto3
from moto import mock_ec2
from unittest.mock import patch
from argparse import Namespace
from awswl import commands
@mock_ec2
@patch('awswl.externalip.get_external_ip', return_value='192.0.2.1')
def test_list_command_lists_ipv4_and_ipv6_cidrs(exip_method):
# Given
options = Namespace()
options.sgid = "sg-123456"
ec2 = boto3.resource('ec2')
sg = ec2.create_security_group(
Description='Security Group for SSH Whitelisting',
GroupName='SSH Whitelist'
)
print("Created security group: {0}".format(sg.GroupId))
Run Code Online (Sandbox Code Playgroud)
而错误:
Testing started at 16:46 ...
/path/.virtualenvs/awswl-Ir8BWU8l/bin/python "/path/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/173.4301.16/PyCharm.app/Contents/helpers/pycharm/_jb_pytest_runner.py" --target test_commands.py::test_list_command_lists_ipv4_and_ipv6_cidrs
Launching py.test with arguments test_commands.py::test_list_command_lists_ipv4_and_ipv6_cidrs in /path/awswl/tests
============================= test session starts ==============================
platform darwin -- Python …Run Code Online (Sandbox Code Playgroud)