ionelmc/pytest-benchmark

View on GitHub

Showing 49 of 49 total issues

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

def main():
    parser = make_parser()
    args = parser.parse_args()
    level = Logger.QUIET if args.quiet else Logger.NORMAL
    if args.verbose:
Severity: Minor
Found in src/pytest_benchmark/cli.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 _make_runner has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def _make_runner(self, function_to_benchmark, args, kwargs):
        def runner(loops_range, timer=self._timer):
            gc_enabled = gc.isenabled()
            if self._disable_gc:
                gc.disable()
Severity: Minor
Found in src/pytest_benchmark/fixture.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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

PY311 = sys.version_info[0] == 3 and sys.version_info[1] >= 11
Severity: Major
Found in src/pytest_benchmark/compat.py and 1 other location - About 1 hr to fix
src/pytest_benchmark/compat.py on lines 3..3

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 38.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

PY38 = sys.version_info[0] == 3 and sys.version_info[1] >= 8
Severity: Major
Found in src/pytest_benchmark/compat.py and 1 other location - About 1 hr to fix
src/pytest_benchmark/compat.py on lines 4..4

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 38.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    def __init__(self, config):
        self.verbose = config.getoption('benchmark_verbose')
        self.quiet = False if self.verbose else config.getoption('benchmark_quiet')
        level = Logger.QUIET if self.quiet else Logger.NORMAL
        if self.verbose:
Severity: Minor
Found in src/pytest_benchmark/session.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 handle_saving has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def handle_saving(self):
        save = self.save or self.autosave
        if save or self.json:
            if not self.benchmarks:
                if not self.disabled:
Severity: Minor
Found in src/pytest_benchmark/session.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 exec_in_env has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def exec_in_env():
    env_path = base_path / '.tox' / 'bootstrap'
    if sys.platform == 'win32':
        bin_path = env_path / 'Scripts'
    else:
Severity: Minor
Found in ci/bootstrap.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 _raw_pedantic has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def _raw_pedantic(self, target, args=(), kwargs=None, setup=None, rounds=1, warmup_rounds=0, iterations=1):
Severity: Major
Found in src/pytest_benchmark/fixture.py - About 50 mins to fix

    Function pedantic has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def pedantic(self, target, args=(), kwargs=None, setup=None, rounds=1, warmup_rounds=0, iterations=1):
    Severity: Major
    Found in src/pytest_benchmark/fixture.py - About 50 mins to fix

      Function _tooltip_data has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def _tooltip_data(self, node, value, x, y, classes=None, xlabel=None):
      Severity: Major
      Found in src/pytest_benchmark/histogram.py - About 50 mins to fix

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

        def pytest_benchmark_scale_unit(config, unit, benchmarks, best, worst, sort):
        Severity: Minor
        Found in src/pytest_benchmark/plugin.py - About 45 mins to fix

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

              def __init__(self, columns, sort, histogram, name_format, logger, scale_unit):
          Severity: Minor
          Found in src/pytest_benchmark/table.py - About 45 mins to fix

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

            def pytest_benchmark_scale_unit(config, unit, benchmarks, best, worst, sort):
            Severity: Minor
            Found in src/pytest_benchmark/hookspec.py - About 45 mins to fix

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

              def compute_baseline_scale(baseline, value, width):
                  if not width:
                      return ''
                  if value == baseline:
                      return ' (1.0)'.ljust(width)
              Severity: Minor
              Found in src/pytest_benchmark/table.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

              Avoid deeply nested control flow statements.
              Open

                                      if self.compare_fail:
                                          for check in self.compare_fail:
                                              fail = check.fails(bench, flat_bench)
                                              if fail:
                                                  self.performance_regressions.append((self.name_format(flat_bench), fail))
              Severity: Major
              Found in src/pytest_benchmark/session.py - About 45 mins to fix

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

                def pytest_runtest_setup(item):
                    marker = item.get_closest_marker('benchmark')
                    if marker:
                        if marker.args:
                            raise ValueError("benchmark mark can't have positional arguments.")
                Severity: Minor
                Found in src/pytest_benchmark/plugin.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(self, hosts, index, doctype, project_name, logger, default_machine_id=None):
                Severity: Minor
                Found in src/pytest_benchmark/storage/elasticsearch.py - About 45 mins to fix

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

                  def pytest_benchmark_generate_json(config, benchmarks, include_data, machine_info, commit_info):
                  Severity: Minor
                  Found in src/pytest_benchmark/hookspec.py - About 35 mins to fix

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

                    def pytest_benchmark_generate_json(config, benchmarks, include_data, machine_info, commit_info):
                    Severity: Minor
                    Found in src/pytest_benchmark/plugin.py - About 35 mins to fix

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

                      def make_histogram(output_prefix, name, benchmarks, unit, adjustment):
                      Severity: Minor
                      Found in src/pytest_benchmark/histogram.py - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language