:py:mod:`pytest` ================ .. py:module:: pytest .. autoapi-nested-parse:: Pytest plugin for E3. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pytest._State Functions ~~~~~~~~~ .. autoapisummary:: pytest.require_tool pytest.pytest_addoption pytest.set_git_env_config pytest.env_protect pytest.pytest_configure pytest.pytest_sessionfinish pytest.fix_coverage_paths pytest.pytest_runtest_makereport Attributes ~~~~~~~~~~ .. autoapisummary:: pytest.msg pytest._state pytest.IN_CI_MODE pytest.DEFAULT_EXCLUDE_LIST .. py:data:: msg :value: 'The e3.pytest plugin requires the pytest package' .. py:class:: _State .. py:attribute:: test_errors :type: bool :value: False .. py:data:: _state .. py:data:: IN_CI_MODE .. py:data:: DEFAULT_EXCLUDE_LIST :value: ('all: no cover', 'if TYPE_CHECKING:', '@abstractmethod', '# os-specific', 'defensive code',... .. py:function:: require_tool(toolname: str) -> collections.abc.Callable Require a specific tool to run the test. When in "CI" mode, a missing tool generates an error. In other modes the test is just skipped. :param toolname: name of a tool, e.g. git .. py:function:: pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None Pytest hook to add e3-specific command line options. :param parser: pytest parser to add options to :param pluginmanager: pytest plugin manager (unused but required by pytest hook) .. py:function:: set_git_env_config() -> None Set the Git environment configuration. This function is called by the env_protect fixture to ensure that the Git environment configuration is set to a known state. Set the `init.defaultbranch` to `default_branch` to ensure that the default branch is not assumed to be `master` or `main`. The best practice when writing test is to either explicitely name the branch or to get the value with `git branch --show-current` .. py:function:: env_protect(request: FixtureRequest) -> collections.abc.Generator[None, None, None] Protection against environment change. The fixture is enabled for all tests and does the following: * store/restore env between tests * create a temporary directory and do a cd to it before each test. The directory is automatically removed when test ends :param request: pytest fixture request .. py:function:: pytest_configure(config: Config) -> None Pytest hook to configure e3-specific settings. :param config: pytest configuration object .. py:function:: pytest_sessionfinish(session: Session, exitstatus: int) -> None Manage the exit code depending on if errors were detected or not. :param session: pytest session :param exitstatus: pytest exit status (unused but required by pytest hook) .. py:function:: fix_coverage_paths(origin_dir: str, new_dir: str, cov_db: str) -> None Fix coverage paths. :param origin_dir: path to the package directory, e.g. .tox/py311-cov-xdist/lib/python3.11/site-packages/e3 :param new_dir: path to the dir that should be visible instead of origin_dir e.g. src/ :param cov_db: path to the .coverage database .. py:function:: pytest_runtest_makereport(item: Item, call: CallInfo[None]) -> None Generate results file. When the variable results_dir is set to an existing directory, the testsuite will generate results file in "anod" format. :param item: pytest test item (unused but required by pytest hook) :param call: pytest call information (unused but required by pytest hook)