pytest_copie.plugin

A pytest plugin to build copier project from a template.

Classes

Copie

Class to provide convenient access to the copier API.

Result

Holds the captured result of the copier project generation.

Functions

copie(request, tmp_path, _copier_config_file[, parent_tpl])

Yield an instance of the Copie helper class.

copie_session(request, tmp_path_factory, ...)

Yield an instance of the Copie helper class.

pytest_addoption(parser)

Add option to the pytest command.

pytest_configure(config)

Force the template path to be absolute to protect ourselves from fixtures that changes path.

Module Contents

class pytest_copie.plugin.Copie[source]

Class to provide convenient access to the copier API.

copy(extra_answers={}, template_dir=None, vcs_ref='HEAD')[source]

Create a copier Project from the template and return the associated Result object.

Parameters:
extra_answers : dict

extra answers to pass to the Copie object and overwrite the default ones

template_dir : Optional[pathlib.Path]

the path to the template to use to create the project instead of the default “.”.

vcs_ref : str

the commit hash, tag or branch to use from the template repo, for the copy

Returns:

the result of the copier project generation

Return type:

Result

git()[source]

A handle to allow execution of git commands during tests.

Return type:

plumbum.machines.LocalCommand

update(result, extra_answers=None, vcs_ref='HEAD')[source]

Update a copier Project from the template and return the associated Result object, returns a new Result.

Parameters:
result : Result

results obtained when the project was first created

extra_answers : Optional[dict]

extra answers to pass to the Copie object and overwrite the default ones

vcs_ref : str

the commit/tag to use for the update

Returns:

the result of the copier project update

Return type:

Result

config_file : pathlib.Path[source]

The path to the copier config file.

counter : int = 0[source]

A counter to keep track of the number of projects created.

default_template_dir : pathlib.Path[source]

The path to the default template to use to create the project.

parent_result : Result | None = None[source]

Template generated by the parent template to be used in combination with default_template.

test_dir : pathlib.Path[source]

The directory where the project will be created.

class pytest_copie.plugin.Result[source]

Holds the captured result of the copier project generation.

answers : dict[source]

The answers used to generate the project.

exception : Exception | SystemExit | None = None[source]

The exception raised during the copier project generation.

exit_code : str | int | None = 0[source]

The exit code of the copier project generation.

project_dir : pathlib.Path | None = None[source]

The path to the generated project.

pytest_copie.plugin.copie(request, tmp_path, _copier_config_file, parent_tpl=None)[source]

Yield an instance of the Copie helper class.

The class can then be used to generate a project from a template.

Parameters:
request : Union[pytest.FixtureRequest, None]

the pytest request object (None when used outside of pytest)

tmp_path : pathlib.Path

the temporary directory

_copier_config_file : pathlib.Path

the temporary copier config file

parent_tpl : Optional[pathlib.Path]

the path to the parent template directory, must be provided when used outside of pytest.

Returns:

the object instance, ready to copy !

Return type:

Generator

pytest_copie.plugin.copie_session(request, tmp_path_factory, _copier_config_file)[source]

Yield an instance of the Copie helper class.

The class can then be used to generate a project from a template.

Parameters:
request

the pytest request object

tmp_path_factory : _pytest.tmpdir.TempPathFactory

the temporary directory

_copier_config_file : pathlib.Path

the temporary copier config file

Returns:

the object instance, ready to copy !

Return type:

Generator

pytest_copie.plugin.pytest_addoption(parser)[source]

Add option to the pytest command.

pytest_copie.plugin.pytest_configure(config)[source]

Force the template path to be absolute to protect ourselves from fixtures that changes path.