Ensure setup_method resets state (#4928)
This commit is contained in:
parent
0ed34cbe7e
commit
cbe787add3
@ -173,7 +173,7 @@ class BaseMockAWS:
|
|||||||
# Special case for UnitTests-class
|
# Special case for UnitTests-class
|
||||||
is_test_method = attr.startswith(unittest.TestLoader.testMethodPrefix)
|
is_test_method = attr.startswith(unittest.TestLoader.testMethodPrefix)
|
||||||
should_reset = False
|
should_reset = False
|
||||||
if attr == "setUp":
|
if attr in ["setUp", "setup_method"]:
|
||||||
should_reset = True
|
should_reset = True
|
||||||
elif not has_setup_method and is_test_method:
|
elif not has_setup_method and is_test_method:
|
||||||
should_reset = True
|
should_reset = True
|
||||||
|
@ -5,7 +5,7 @@ import sure # noqa # pylint: disable=unused-import
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
from moto import mock_ec2, mock_s3, settings
|
from moto import mock_ec2, mock_kinesis, mock_s3, settings
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -159,6 +159,25 @@ class TestWithSetupMethod:
|
|||||||
s3.head_bucket(Bucket="unknown_bucket")
|
s3.head_bucket(Bucket="unknown_bucket")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_kinesis
|
||||||
|
class TestKinesisUsingSetupMethod:
|
||||||
|
def setup_method(self, *args):
|
||||||
|
self.stream_name = "test_stream"
|
||||||
|
self.boto3_kinesis_client = boto3.client("kinesis", region_name="us-east-1")
|
||||||
|
self.boto3_kinesis_client.create_stream(
|
||||||
|
StreamName=self.stream_name, ShardCount=1
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_stream_creation(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_stream_recreation(self):
|
||||||
|
# The setup-method will run again for this test
|
||||||
|
# The fact that it passes, means the state was reset
|
||||||
|
# Otherwise it would complain about a stream already existing
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
class TestWithInvalidSetupMethod:
|
class TestWithInvalidSetupMethod:
|
||||||
def setupmethod(self):
|
def setupmethod(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user