pytest_flakefighters.flakefighters.deflaker

This module implements the DeFlaker FlakeFighter.

Module Contents

Classes

DeFlaker

A python equivalent of the DeFlaker algorithm from Bell et al. (2019).

class pytest_flakefighters.flakefighters.deflaker.DeFlaker(run_live: bool, root: str = '.', source_commit: str = None, target_commit: str = None)

Bases: pytest_flakefighters.flakefighters.abstract_flakefighter.FlakeFighter

A python equivalent of the DeFlaker algorithm from Bell et al. (2019). Given the subtle differences between JUnit and pytest, this is not intended to be an exact port, but it follows the same general methodology of checking whether covered code has been changed between commits.

Variables:
  • run_live – Run detection “live” after each test. Otherwise run as a postprocessing step after the test suite.

  • root – The root directory of the Git repository.

  • source_commit – The source (older) commit hash. Defaults to HEAD^ (the previous commit to target).

  • target_commit – The target (newer) commit hash. Defaults to HEAD (the most recent commit).

classmethod from_config(config: dict)

Factory method to create a new instance from a pytest configuration.

params()

Convert the key parameters into a dictionary so that the object can be replicated. :return A dictionary of the parameters used to create the object.

line_modified_by_target_commit(file_path: str, line_no: int) bool

Returns true if the given line in the file has been modified by the present commit.

Parameters:
  • file_path – The file to check.

  • line_no – The line number to check.

_flaky_execution(execution)

Classify an execution as flaky or not. :return: Boolean True of the test is classed as flaky and False otherwise.

flaky_test_live(execution: pytest_flakefighters.database_management.TestExecution)

Classify a failing test as flaky if it does not cover any code which has been changed between the source and target commits. :param execution: The test execution to classify.

flaky_tests_post(run: pytest_flakefighters.database_management.Run) list[bool | None]

Classify failing tests as flaky if any of their executions are flaky. :param run: Run object representing the pytest run, with tests accessible through run.tests.