:py:mod:`pytest_flakefighters.database_management` ================================================== .. py:module:: pytest_flakefighters.database_management .. autoapi-nested-parse:: This module manages all interaction with the test run database. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pytest_flakefighters.database_management.Base pytest_flakefighters.database_management.Run pytest_flakefighters.database_management.ActiveFlakeFighter pytest_flakefighters.database_management.Test pytest_flakefighters.database_management.TestExecution pytest_flakefighters.database_management.TestException pytest_flakefighters.database_management.TracebackEntry pytest_flakefighters.database_management.FlakefighterResult pytest_flakefighters.database_management.Database .. py:class:: Base Bases: :py:obj:`sqlalchemy.orm.DeclarativeBase` Declarative base class for data objects. :ivar id: Unique autoincrementing ID for the object. .. py:attribute:: id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: __test__ :value: False .. py:method:: __tablename__() .. py:class:: Run Bases: :py:obj:`Base` Class to store attributes of a flakefighters run. :ivar start_time: The time the test run was begun. :ivar created_at: The time the entry was added to the database. This is not necessarily equivalent to start_time if the test suite took a long time to run or if the entry was migrated from a separate database. :ivar root: The root directory of the project. :ivar tests: The test suite. :ivar active_flakefighters: The flakefighters that are active on the run. .. py:attribute:: start_time .. py:attribute:: created_at .. py:attribute:: root :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: tests .. py:attribute:: active_flakefighters .. py:class:: ActiveFlakeFighter Bases: :py:obj:`Base` Store relevant information about the active flakefighters. :ivar run_id: Foreign key of the related run. :ivar name: Class name of the flakefighter. :ivar params: The parameterss of the flakefighter. .. py:attribute:: run_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: params :type: sqlalchemy.orm.Mapped[dict] .. py:class:: Test Bases: :py:obj:`Base` Class to store attributes of a test case. :ivar run_id: Foreign key of the related run. :ivar fspath: File system path of the file containing the test definition. :ivar line_no: Line number of the test definition. :ivar name: Name of the test case. :ivar skipped: Boolean true if the test was skipped, else false. :ivar executions: List of execution attempts. :ivar flakefighter_results: List of test-level flakefighter results. .. note:: Execution-level flakefighter results will be stored inside the individual TestExecution objects .. py:property:: flaky :type: bool Return whether a test (or any of its executions) has been marked as flaky by any flakefighter. .. py:attribute:: run_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: fspath :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: line_no :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: skipped :type: sqlalchemy.orm.Mapped[bool] .. py:attribute:: executions .. py:attribute:: flakefighter_results .. py:class:: TestExecution Bases: :py:obj:`Base` Class to store attributes of a test outcome. :ivar test_id: Foreign key of the related test. :ivar outcome: Outcome of the test. One of "passed", "failed", or "skipped". :ivar stdout: The captured stdout string. :ivar stedrr: The captured stderr string. :ivar start_time: The start time of the test. :ivar end_time: The end time of the test. :ivar coverage: The line coverage of the test. :ivar flakefighter_results: The execution-level flakefighter results. :ivar exception: The exception associated with the test if one was thrown. .. py:property:: flaky :type: bool Return whether a test (or any of its executions) has been marked as flaky by any flakefighter. .. py:attribute:: __tablename__ :value: 'test_execution' .. py:attribute:: test_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: outcome :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: stdout :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: stderr :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: report :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: start_time :type: sqlalchemy.orm.Mapped[datetime.datetime] .. py:attribute:: end_time :type: sqlalchemy.orm.Mapped[datetime.datetime] .. py:attribute:: coverage :type: sqlalchemy.orm.Mapped[dict] .. py:attribute:: flakefighter_results .. py:attribute:: exception .. py:class:: TestException Bases: :py:obj:`Base` Class to store information about the exceptions that cause tests to fail. :ivar execution_id: Foreign key of the related execution. :ivar name: Name of the exception. :traceback: The full stack of traceback entries. .. py:attribute:: __tablename__ :value: 'test_exception' .. py:attribute:: execution_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: traceback .. py:class:: TracebackEntry Bases: :py:obj:`Base` Class to store attributes of entries in the stack trace. :ivar exception_id: Foreign key of the related exception. :ivar path: Filepath of the source file. :ivar lineno: Line number of the executed statement. :ivar colno: Column number of the executed statement. :ivar statement: The executed statement. :ivar source: The surrounding source code. .. py:attribute:: exception_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: path :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: lineno :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: colno :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: statement :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: source :type: sqlalchemy.orm.Mapped[str] .. py:class:: FlakefighterResult Bases: :py:obj:`Base` Class to store flakefighter results. :ivar test_execution_id: Foreign key of the related test execution. Should not be set if test_id is present. :ivar test_id: Foreign key of the related test. Should not be set if test_execution_id is present. :ivar name: Name of the flakefighter. :ivar flaky: Boolean true if the test (execution) was classified as flaky. .. py:property:: classification Return the classification as a string. "flaky" if the test was classified as flaky, else "genuine". .. py:attribute:: __tablename__ :value: 'flakefighter_result' .. py:attribute:: test_execution_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: test_id :type: sqlalchemy.orm.Mapped[int] .. py:attribute:: name :type: sqlalchemy.orm.Mapped[str] .. py:attribute:: flaky :type: sqlalchemy.orm.Mapped[bool] .. py:attribute:: __table_args__ :value: () .. py:class:: Database(url: str, load_max_runs: int = None, store_max_runs: int = None, time_immemorial: Union[datetime.timedelta, str] = None) Class to handle database setup and interaction. :ivar engine: The database engine. :ivar store_max_runs: The maximum number of previous runs that should be stored. If the database exceeds this size, older runs will be pruned to make space for newer ones. :ivar time_immemorial: Time before which runs should not be considered. Runs before this date will be pruned when saving new runs. :ivar previous_runs: List of previous flakefighter runs with most recent first. .. py:method:: save(run: Run) Save the given run into the database. .. py:method:: load_runs(limit: int = None) Load runs from the database. :param limit: The maximum number of runs to return (these will be most recent runs).