Address pytest warnings (#3629)

* Address `boto` deprecation warnings

This commit eliminates the following warning:

../boto/ec2/connection.py:582:
  PendingDeprecationWarning: The current get_all_instances implementation will be replaced with get_all_reservations.

`boto` isn't likely to ever make good on this warning, but doing the replacement will
declutter the `moto` test output.

* Remove `invoke_lambda` tracebacks from unit test logging

If an exception is encountered, the details are returned in the response payload.
Printing the traceback was just adding noise to the pytest output.

* Use known AMIs in unit tests

This commit eliminates the following warning in the pytest output:

`PendingDeprecationWarning: Could not find AMI with image-id:ami-123456, in the near future this will cause an error.`

Known, pre-loaded AMI image ids are used instead of random ids that don't actually
exist in the moto backend.  The integrity of the tests is unaffected by this change.

A test has been added to provide explicit coverage of the PendingDeprecationWarning
raised when an invalid AMI image id is passed to moto.
This commit is contained in:
Brian Pandola 2021-01-29 03:31:56 -08:00 committed by GitHub
commit f4b81e69b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 98 additions and 72 deletions

View file

@ -21,38 +21,38 @@ def test_basic_connect():
@mock_ec2_deprecated
def test_basic_decorator():
conn = boto.connect_ec2("the_key", "the_secret")
list(conn.get_all_instances()).should.equal([])
list(conn.get_all_reservations()).should.equal([])
@pytest.mark.network
def test_context_manager():
conn = boto.connect_ec2("the_key", "the_secret")
with pytest.raises(EC2ResponseError):
conn.get_all_instances()
conn.get_all_reservations()
with mock_ec2_deprecated():
conn = boto.connect_ec2("the_key", "the_secret")
list(conn.get_all_instances()).should.equal([])
list(conn.get_all_reservations()).should.equal([])
with pytest.raises(EC2ResponseError):
conn = boto.connect_ec2("the_key", "the_secret")
conn.get_all_instances()
conn.get_all_reservations()
@pytest.mark.network
def test_decorator_start_and_stop():
conn = boto.connect_ec2("the_key", "the_secret")
with pytest.raises(EC2ResponseError):
conn.get_all_instances()
conn.get_all_reservations()
mock = mock_ec2_deprecated()
mock.start()
conn = boto.connect_ec2("the_key", "the_secret")
list(conn.get_all_instances()).should.equal([])
list(conn.get_all_reservations()).should.equal([])
mock.stop()
with pytest.raises(EC2ResponseError):
conn.get_all_instances()
conn.get_all_reservations()
@mock_ec2_deprecated
@ -69,11 +69,11 @@ def test_decorater_wrapped_gets_set():
class Tester(object):
def test_the_class(self):
conn = boto.connect_ec2()
list(conn.get_all_instances()).should.have.length_of(0)
list(conn.get_all_reservations()).should.have.length_of(0)
def test_still_the_same(self):
conn = boto.connect_ec2()
list(conn.get_all_instances()).should.have.length_of(0)
list(conn.get_all_reservations()).should.have.length_of(0)
@mock_s3_deprecated

View file

@ -6,6 +6,7 @@ from boto.sqs.message import Message
from boto.ec2 import EC2Connection
from moto import mock_sqs_deprecated, mock_ec2_deprecated
from tests import EXAMPLE_AMI_ID
class TestNestedDecorators(unittest.TestCase):
@ -25,4 +26,4 @@ class TestNestedDecorators(unittest.TestCase):
self.setup_sqs_queue()
conn = EC2Connection()
conn.run_instances("ami-123456")
conn.run_instances(EXAMPLE_AMI_ID)