pytest¶
Pytest plugin for E3.
Module Contents¶
Classes¶
Functions¶
|
Require a specific tool to run the test. |
|
Pytest hook to add e3-specific command line options. |
|
Set the Git environment configuration. |
|
Protection against environment change. |
|
Pytest hook to configure e3-specific settings. |
|
Manage the exit code depending on if errors were detected or not. |
|
Fix coverage paths. |
Generate results file. |
Attributes¶
- pytest.msg = 'The e3.pytest plugin requires the pytest package'¶
- pytest._state¶
- pytest.IN_CI_MODE¶
- pytest.DEFAULT_EXCLUDE_LIST = ('all: no cover', 'if TYPE_CHECKING:', '@abstractmethod', '# os-specific', 'defensive code',...¶
- pytest.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.
- Parameters:
toolname – name of a tool, e.g. git
- pytest.pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) None¶
Pytest hook to add e3-specific command line options.
- Parameters:
parser – pytest parser to add options to
pluginmanager – pytest plugin manager (unused but required by pytest hook)
- pytest.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
- pytest.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
- Parameters:
request – pytest fixture request
- pytest.pytest_configure(config: Config) None¶
Pytest hook to configure e3-specific settings.
- Parameters:
config – pytest configuration object
- pytest.pytest_sessionfinish(session: Session, exitstatus: int) None¶
Manage the exit code depending on if errors were detected or not.
- Parameters:
session – pytest session
exitstatus – pytest exit status (unused but required by pytest hook)
- pytest.fix_coverage_paths(origin_dir: str, new_dir: str, cov_db: str) None¶
Fix coverage paths.
- Parameters:
origin_dir – path to the package directory, e.g. .tox/py311-cov-xdist/lib/python3.11/site-packages/e3
new_dir – path to the dir that should be visible instead of origin_dir e.g. src/
cov_db – path to the .coverage database
- pytest.pytest_runtest_makereport(item: Item, call: CallInfo[None]) collections.abc.Generator[None, Any, None]¶
Generate results file.
When the variable results_dir is set to an existing directory, the testsuite will generate results file in “anod” format.
- Parameters:
item – pytest test item (unused but required by pytest hook)
call – pytest call information (unused but required by pytest hook)