Non-unittest classes use a lowercase setup-method (#4833)
This commit is contained in:
parent
bb6fb1200f
commit
fbefae59c5
@ -137,11 +137,15 @@ class BaseMockAWS:
|
||||
c for c in klass.__mro__ if c not in [unittest.TestCase, object]
|
||||
]
|
||||
# Get a list of all userdefined methods
|
||||
supermethods = itertools.chain(
|
||||
*[get_direct_methods_of(c) for c in superclasses]
|
||||
supermethods = list(
|
||||
itertools.chain(*[get_direct_methods_of(c) for c in superclasses])
|
||||
)
|
||||
# Check whether the user has overridden the setUp-method
|
||||
has_setup_method = "setUp" in supermethods
|
||||
has_setup_method = (
|
||||
("setUp" in supermethods and unittest.TestCase in klass.__mro__)
|
||||
or "setup" in supermethods
|
||||
or "setup_method" in supermethods
|
||||
)
|
||||
|
||||
for attr in itertools.chain(direct_methods, defined_classes):
|
||||
if attr.startswith("_"):
|
||||
|
@ -109,8 +109,9 @@ class TesterWithStaticmethod(object):
|
||||
|
||||
|
||||
@mock_s3
|
||||
class TestWithSetup(unittest.TestCase):
|
||||
class TestWithSetup_UppercaseU(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# This method will be executed automatically, provided we extend the TestCase-class
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
s3.create_bucket(Bucket="mybucket")
|
||||
|
||||
@ -124,6 +125,53 @@ class TestWithSetup(unittest.TestCase):
|
||||
s3.head_bucket(Bucket="unknown_bucket")
|
||||
|
||||
|
||||
@mock_s3
|
||||
class TestWithSetup_LowercaseU:
|
||||
def setup(self, *args):
|
||||
# This method will be executed automatically using pytest
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
s3.create_bucket(Bucket="mybucket")
|
||||
|
||||
def test_should_find_bucket(self):
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
assert s3.head_bucket(Bucket="mybucket") is not None
|
||||
|
||||
def test_should_not_find_unknown_bucket(self):
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
with pytest.raises(ClientError):
|
||||
s3.head_bucket(Bucket="unknown_bucket")
|
||||
|
||||
|
||||
@mock_s3
|
||||
class TestWithSetupMethod:
|
||||
def setup_method(self, *args):
|
||||
# This method will be executed automatically using pytest
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
s3.create_bucket(Bucket="mybucket")
|
||||
|
||||
def test_should_find_bucket(self):
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
assert s3.head_bucket(Bucket="mybucket") is not None
|
||||
|
||||
def test_should_not_find_unknown_bucket(self):
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
with pytest.raises(ClientError):
|
||||
s3.head_bucket(Bucket="unknown_bucket")
|
||||
|
||||
|
||||
@mock_s3
|
||||
class TestWithInvalidSetupMethod:
|
||||
def setupmethod(self):
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
s3.create_bucket(Bucket="mybucket")
|
||||
|
||||
def test_should_not_find_bucket(self):
|
||||
# Name of setupmethod is not recognized, so it will not be executed
|
||||
s3 = boto3.client("s3", region_name="us-east-1")
|
||||
with pytest.raises(ClientError):
|
||||
s3.head_bucket(Bucket="mybucket")
|
||||
|
||||
|
||||
@mock_s3
|
||||
class TestWithPublicMethod(unittest.TestCase):
|
||||
def ensure_bucket_exists(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user