我是 moto 和 aws 的新手,所以我正在尝试为 aws 中的简单 ELB 检查器编写一些简单的测试用例。
我在这里阅读了 moto 页面:
https://github.com/spulec/moto
我在这里遵循 boto3 指南:
https://boto3.readthedocs.io/en/latest/reference/services/elb.html
但我认为我不了解如何将 moto 与 boto3 一起使用。以下是我的代码和错误,任何帮助将不胜感激。
# # -*- coding: utf-8 -*-
from .context import elb_tools
from nose.tools import set_trace;
import unittest
from moto.elb import mock_elb
import boto3
class TestElbTools(unittest.TestCase):
"""Basic test cases."""
def setUp(self):
pass
@mock_elb
def test_check_elb_has_attached_instances(self):
empty_elb = mock_elb
mock_elb.describe_load_balancers()
if __name__ == '__main__':
unittest.main()
输出:
D:\dev\git_repos\platform-health>nosetests
E
======================================================================
ERROR: test_check_elb_has_attached_instances (test_orphan_elb_finder.test_elb_tools.TestElbTools)
----------------------------------------------------------------------
Traceback (most recent call last):
File "d:\apps\python\python27\lib\site-packages\moto\core\models.py", line 71, in wrapper
result = func(*args, **kwargs)
File "D:\dev\git_repos\platform-health\tests\unit_tests\test_orphan_elb_finder\test_elb_tools.py", line 22, in test_check_elb_has_attached_instances
mock_elb.describe_load_balancers()
AttributeError: 'function' object has no attribute 'describe_load_balancers'
----------------------------------------------------------------------
Ran 1 test in 0.561s
FAILED (errors=1)