localstack/localstack

View on GitHub
localstack/testing/pytest/fixtures.py

Summary

Maintainability
F
1 wk
Test Coverage

File fixtures.py has 1680 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import contextlib
import dataclasses
import json
import logging
import os
Severity: Major
Found in localstack/testing/pytest/fixtures.py - About 4 days to fix

    Function deploy_cfn_template has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def deploy_cfn_template(
        cleanup_stacks,
        cleanup_changesets,
        is_change_set_created_and_available,
        is_change_set_finished,
    Severity: Minor
    Found in localstack/testing/pytest/fixtures.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function create_user has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_user(aws_client):
        usernames = []
    
        def _create_user(**kwargs):
            if "UserName" not in kwargs:
    Severity: Minor
    Found in localstack/testing/pytest/fixtures.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function create_role has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_role(aws_client):
        role_names = []
    
        def _create_role(iam_client=None, **kwargs):
            if not kwargs.get("RoleName"):
    Severity: Minor
    Found in localstack/testing/pytest/fixtures.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _deploy has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def _deploy(
    Severity: Major
    Found in localstack/testing/pytest/fixtures.py - About 1 hr to fix

      Function check_lambda_logs has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def check_lambda_logs(aws_client):
          def _check_logs(func_name: str, expected_lines: List[str] = None) -> List[str]:
              if not expected_lines:
                  expected_lines = []
              log_events = get_lambda_logs(func_name, logs_client=aws_client.logs)
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function create_rest_apigw has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def create_rest_apigw(aws_client_factory):
          rest_apis = []
      
          def _create_apigateway_function(**kwargs):
              region_name = kwargs.pop("region_name", None)
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function aws_http_client_factory has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def aws_http_client_factory(aws_session):
          """
          Returns a factory for creating new ``SigningHttpClient`` instances using a configurable botocore request signer.
          The default signer is a SigV4QueryAuth. The credentials are extracted from the ``boto3_sessions`` fixture that
          transparently uses your global profile when TEST_TARGET=AWS_CLOUD, or test credentials when running against
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function kms_create_key has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def kms_create_key(aws_client_factory):
          key_ids = []
      
          def _create_key(region_name: str = None, **kwargs):
              if "Description" not in kwargs:
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function kms_create_grant has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def kms_create_grant(kms_create_key, aws_client):
          grants = []
      
          def _create_grant(**kwargs):
              # Just a random ARN, since KMS in LocalStack currently doesn't validate GranteePrincipal,
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function transcribe_create_job has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def transcribe_create_job(s3_bucket, aws_client):
          job_names = []
      
          def _create_job(audio_file: str, params: Optional[dict[str, Any]] = None) -> str:
              s3_key = "test-clip.wav"
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function pytest_collection_modifyitems has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def pytest_collection_modifyitems(config: Config, items: list[Item]):
          only_localstack = pytest.mark.skipif(
              is_aws_cloud(),
              reason="test only applicable if run against localstack",
          )
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function create_lambda_function has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def create_lambda_function(aws_client, wait_until_lambda_ready, lambda_su_role):
          lambda_arns_and_clients = []
          log_groups = []
          lambda_client = aws_client.lambda_
          logs_client = aws_client.logs
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _create_role_with_policy has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def _create_role_with_policy(
      Severity: Minor
      Found in localstack/testing/pytest/fixtures.py - About 45 mins to fix

        Function factory has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def factory(
        Severity: Minor
        Found in localstack/testing/pytest/fixtures.py - About 45 mins to fix

          Function s3_create_bucket has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def s3_create_bucket(s3_empty_bucket, aws_client):
              buckets = []
          
              def factory(**kwargs) -> str:
                  if "Bucket" not in kwargs:
          Severity: Minor
          Found in localstack/testing/pytest/fixtures.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function sqs_receive_num_messages has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def sqs_receive_num_messages(sqs_receive_messages_delete):
              def factory(queue_url: str, expected_messages: int, max_iterations: int = 3):
                  all_messages = []
                  for _ in range(max_iterations):
                      try:
          Severity: Minor
          Found in localstack/testing/pytest/fixtures.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _create_policy_with_doc has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _create_policy_with_doc(effect, actions, policy_name=None, resource=None, iam_client=None):
          Severity: Minor
          Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

            Function deploy_cfn_template has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def deploy_cfn_template(
            Severity: Minor
            Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Function sns_wait_for_topic_delete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def sns_wait_for_topic_delete(aws_client):
                  def wait_for_topic_delete(topic_arn: str) -> None:
                      def wait():
                          try:
                              aws_client.sns.get_topic_attributes(TopicArn=topic_arn)
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function wait_until_lambda_ready has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def wait_until_lambda_ready(aws_client):
                  def _wait_until_ready(function_name: str, qualifier: str = None, client=None):
                      client = client or aws_client.lambda_
              
                      def _is_not_pending():
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function route53_hosted_zone has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def route53_hosted_zone(aws_client):
                  hosted_zones = []
              
                  def factory(**kwargs):
                      if "Name" not in kwargs:
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function dynamodb_create_table has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def dynamodb_create_table(dynamodb_wait_for_table_active, aws_client):
                  # beware, this swallows exception in create_dynamodb_table utility function
                  tables = []
              
                  def factory(**kwargs):
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function create_lambda_function_aws has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def create_lambda_function_aws(aws_client):
                  lambda_arns = []
              
                  def _create_lambda_function(**kwargs):
                      def _create_function():
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function kms_create_alias has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def kms_create_alias(kms_create_key, aws_client):
                  aliases = []
              
                  def _create_alias(**kwargs):
                      if "AliasName" not in kwargs:
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function appsync_create_api has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def appsync_create_api(aws_client):
                  graphql_apis = []
              
                  def factory(**kwargs):
                      if "name" not in kwargs:
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function register_extension has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def register_extension(s3_bucket, aws_client):
                  cfn_client = aws_client.cloudformation
                  extensions_arns = []
              
                  def _register(extension_name, extension_type, artifact_path):
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function is_change_set_finished has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def is_change_set_finished(aws_client):
                  def _is_change_set_finished(change_set_id: str, stack_name: Optional[str] = None):
                      def _inner():
                          kwargs = {"ChangeSetName": change_set_id}
                          if stack_name:
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function sqs_receive_messages_delete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def sqs_receive_messages_delete(aws_client):
                  def factory(
                      queue_url: str,
                      expected_messages: Optional[int] = None,
                      wait_time: Optional[int] = 5,
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function s3_empty_bucket has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def s3_empty_bucket(aws_client):
                  """
                  Returns a factory that given a bucket name, deletes all objects and deletes all object versions
                  """
              
              
              Severity: Minor
              Found in localstack/testing/pytest/fixtures.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              There are no issues that match your filters.

              Category
              Status