Skip to content

A Copier plugin for pytest to help testing Copier templates

License

Notifications You must be signed in to change notification settings

noirbizarre/pytest-copier

Repository files navigation

pytest-copier

CI pre-commit.ci status PyPI PyPI - License

A pytest plugin to help testing Copier templates

Note: this was a PoC and it will receive the full code and documentation very soon.

Getting started

Install pytest-copier:

# pip
pip install pytest-copier
# pipenv
pipenv install pytest-copier
# PDM
pdm add pytest-copier

Usage

The copier fixture will allow you to copy a template and run tests against it. It also allows to just test the rendering context. It will also clean up the generated project after the tests have been run.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from pytest_copier import CopierFixture


@pytest.fixture(scope="session")
def copier_defaults() -> dict[str, Any]:
    return {
        "project_name": "Test project",
        "author_email": "[email protected]",
    }


@pytest.fixture(scope="session")
def copier_template_paths() -> Sequence[str]:
    return (
        "template",
        "extensions",
        "copier.yml",
    )


def test_rendered_project(copier: CopierFixture):
    project = copier.copy(project_name="something else")

    assert project.answers["project_name") == "something else"

    some_file = project / "some.file"
    assert some_file.exists()

    output = project.run("do something")
    assert "expected" in output


def test_default_answers_context(copier: CopierFixture):
    ctx = copier.context()

    assert ctx["project_name"] == "Test project"
    assert ctx["project_slug"] == "test-project"


def test_answers_context(copier: CopierFixture):
    ctx = copier.context(project_name="my-project")

    assert ctx["project_name"] == "my-project"
    assert ctx["author_email"] == "[email protected]"

Contributing

Read the dedicated contributing guidelines.

About

A Copier plugin for pytest to help testing Copier templates

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages