pytest-cookies


Namepytest-cookies JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/hackebrot/pytest-cookies
SummaryThe pytest plugin for your Cookiecutter templates. 🍪
upload_time2023-03-22 11:07:29
maintainerRaphael Pierzina
docs_urlNone
authorRaphael Pierzina
requires_python>=3.7
licenseMIT
keywords cookiecutter pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-cookies

[pytest][pytest] is a mature testing framework for Python that is developed
by a thriving and ever-growing community of volunteers. It uses plain assert
statements and regular Python comparisons. At the core of the pytest test
framework is a powerful hook-based plugin system.

**pytest-cookies** is a pytest plugin that comes with a ``cookies`` fixture
which is a wrapper for the [cookiecutter][cookiecutter] API for generating
projects. It helps you verify that your template is working as expected and
takes care of cleaning up after running the tests. 🍪

# Installation

**pytest-cookies** is available for download from [PyPI][pypi] via [pip][pip]:

```text
pip install pytest-cookies
```
This will automatically install [pytest][pytest] and
[cookiecutter][cookiecutter].

# Usage

## Generate a new project

The ``cookies.bake()`` method generates a new project from your template
based on the default values specified in ``cookiecutter.json``:

```python
def test_bake_project(cookies):
    result = cookies.bake(extra_context={"repo_name": "helloworld"})

    assert result.exit_code == 0
    assert result.exception is None

    assert result.project_path.name == "helloworld"
    assert result.project_path.is_dir()

    # The `project` attribute is deprecated
    assert result.project.basename == "helloworld"
    assert result.project.isdir()
```

**Please note that the `project` attribute of the returned `Result` class is
deprecated and will be removed in a future release, please use `project_path`
instead.**

The ``cookies.bake()`` method also accepts the ``extra_context`` keyword
argument that will be passed to cookiecutter. The given dictionary will
override the default values of the template context, effectively allowing you
to test arbitrary user input data.

For more information on injecting extra context, please check out the
[cookiecutter documentation][extra-context].

## Specify the template directory

By default ``cookies.bake()`` looks for a cookiecutter template in the
current directory. This can be overridden on the command line by passing a
``--template`` parameter to pytest:

```text
pytest --template TEMPLATE
```

You can customize the cookiecutter template directory from a test by passing
in the optional ``template`` paramter:

```python
@pytest.fixture
def custom_template(tmpdir):
    template = tmpdir.ensure("cookiecutter-template", dir=True)
    template.join("cookiecutter.json").write('{"repo_name": "example-project"}')

    repo_dir = template.ensure("{{cookiecutter.repo_name}}", dir=True)
    repo_dir.join("README.rst").write("{{cookiecutter.repo_name}}")

    return template


def test_bake_custom_project(cookies, custom_template):
    """Test for 'cookiecutter-template'."""
    result = cookies.bake(template=str(custom_template))

    assert result.exit_code == 0
    assert result.exception is None

    assert result.project_path.name == "example-project"
    assert result.project_path.is_dir()
```

## Keep output directories for debugging

By default ``cookies`` removes baked projects.

However, you can pass the ``keep-baked-projects`` flag if you'd like to keep
them ([it won't clutter][temporary-directories] as pytest only keeps the
three newest temporary directories):

```text
pytest --keep-baked-projects
```

# Community

Contributions are very welcome! If you encounter any problems, please [file
an issue][new-issue] along with a detailed description. Tests can be run with
[tox][tox]. Please make sure all of the tests are green before you submit a
pull request.

You can also support the development of this project by volunteering to
become a maintainer, which means you will be able to triage issues, merge
pull-requests, and publish new releases. If you're interested, please submit
a pull-request to add yourself to the list of [maintainers][community] and
we'll get you started! 🍪

Please note that **pytest-cookies** is released with a [Contributor Code of
Conduct][code-of-conduct]. By participating in this project you agree to
abide by its terms.

# License

Distributed under the terms of the [MIT license][license], **pytest-cookies**
is free and open source software.

[cookiecutter]: https://github.com/audreyr/cookiecutter
[pytest]: https://github.com/pytest-dev/pytest
[pip]: https://pypi.org/project/pip/
[pypi]: https://pypi.org/project/pytest-cookies/
[extra-context]: https://cookiecutter.readthedocs.io/en/latest/advanced/injecting_context.html
[temporary-directories]: https://docs.pytest.org/en/latest/tmpdir.html#the-default-base-temporary-directory
[tox]: https://pypi.org/project/tox/
[new-issue]: https://github.com/hackebrot/pytest-cookies/issues
[code-of-conduct]: https://github.com/hackebrot/pytest-cookies/blob/main/CODE_OF_CONDUCT.md
[community]: https://github.com/hackebrot/pytest-cookies/blob/main/COMMUNITY.md
[license]: https://github.com/hackebrot/pytest-cookies/blob/main/LICENSE

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hackebrot/pytest-cookies",
    "name": "pytest-cookies",
    "maintainer": "Raphael Pierzina",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "raphael@hackebrot.de",
    "keywords": "cookiecutter,pytest",
    "author": "Raphael Pierzina",
    "author_email": "raphael@hackebrot.de",
    "download_url": "https://files.pythonhosted.org/packages/18/2e/11a3e1abb4bbf10e0af3f194ba4c55600de3fe52417ef3594c18d28ecdbe/pytest-cookies-0.7.0.tar.gz",
    "platform": null,
    "description": "# pytest-cookies\n\n[pytest][pytest] is a mature testing framework for Python that is developed\nby a thriving and ever-growing community of volunteers. It uses plain assert\nstatements and regular Python comparisons. At the core of the pytest test\nframework is a powerful hook-based plugin system.\n\n**pytest-cookies** is a pytest plugin that comes with a ``cookies`` fixture\nwhich is a wrapper for the [cookiecutter][cookiecutter] API for generating\nprojects. It helps you verify that your template is working as expected and\ntakes care of cleaning up after running the tests. \ud83c\udf6a\n\n# Installation\n\n**pytest-cookies** is available for download from [PyPI][pypi] via [pip][pip]:\n\n```text\npip install pytest-cookies\n```\nThis will automatically install [pytest][pytest] and\n[cookiecutter][cookiecutter].\n\n# Usage\n\n## Generate a new project\n\nThe ``cookies.bake()`` method generates a new project from your template\nbased on the default values specified in ``cookiecutter.json``:\n\n```python\ndef test_bake_project(cookies):\n    result = cookies.bake(extra_context={\"repo_name\": \"helloworld\"})\n\n    assert result.exit_code == 0\n    assert result.exception is None\n\n    assert result.project_path.name == \"helloworld\"\n    assert result.project_path.is_dir()\n\n    # The `project` attribute is deprecated\n    assert result.project.basename == \"helloworld\"\n    assert result.project.isdir()\n```\n\n**Please note that the `project` attribute of the returned `Result` class is\ndeprecated and will be removed in a future release, please use `project_path`\ninstead.**\n\nThe ``cookies.bake()`` method also accepts the ``extra_context`` keyword\nargument that will be passed to cookiecutter. The given dictionary will\noverride the default values of the template context, effectively allowing you\nto test arbitrary user input data.\n\nFor more information on injecting extra context, please check out the\n[cookiecutter documentation][extra-context].\n\n## Specify the template directory\n\nBy default ``cookies.bake()`` looks for a cookiecutter template in the\ncurrent directory. This can be overridden on the command line by passing a\n``--template`` parameter to pytest:\n\n```text\npytest --template TEMPLATE\n```\n\nYou can customize the cookiecutter template directory from a test by passing\nin the optional ``template`` paramter:\n\n```python\n@pytest.fixture\ndef custom_template(tmpdir):\n    template = tmpdir.ensure(\"cookiecutter-template\", dir=True)\n    template.join(\"cookiecutter.json\").write('{\"repo_name\": \"example-project\"}')\n\n    repo_dir = template.ensure(\"{{cookiecutter.repo_name}}\", dir=True)\n    repo_dir.join(\"README.rst\").write(\"{{cookiecutter.repo_name}}\")\n\n    return template\n\n\ndef test_bake_custom_project(cookies, custom_template):\n    \"\"\"Test for 'cookiecutter-template'.\"\"\"\n    result = cookies.bake(template=str(custom_template))\n\n    assert result.exit_code == 0\n    assert result.exception is None\n\n    assert result.project_path.name == \"example-project\"\n    assert result.project_path.is_dir()\n```\n\n## Keep output directories for debugging\n\nBy default ``cookies`` removes baked projects.\n\nHowever, you can pass the ``keep-baked-projects`` flag if you'd like to keep\nthem ([it won't clutter][temporary-directories] as pytest only keeps the\nthree newest temporary directories):\n\n```text\npytest --keep-baked-projects\n```\n\n# Community\n\nContributions are very welcome! If you encounter any problems, please [file\nan issue][new-issue] along with a detailed description. Tests can be run with\n[tox][tox]. Please make sure all of the tests are green before you submit a\npull request.\n\nYou can also support the development of this project by volunteering to\nbecome a maintainer, which means you will be able to triage issues, merge\npull-requests, and publish new releases. If you're interested, please submit\na pull-request to add yourself to the list of [maintainers][community] and\nwe'll get you started! \ud83c\udf6a\n\nPlease note that **pytest-cookies** is released with a [Contributor Code of\nConduct][code-of-conduct]. By participating in this project you agree to\nabide by its terms.\n\n# License\n\nDistributed under the terms of the [MIT license][license], **pytest-cookies**\nis free and open source software.\n\n[cookiecutter]: https://github.com/audreyr/cookiecutter\n[pytest]: https://github.com/pytest-dev/pytest\n[pip]: https://pypi.org/project/pip/\n[pypi]: https://pypi.org/project/pytest-cookies/\n[extra-context]: https://cookiecutter.readthedocs.io/en/latest/advanced/injecting_context.html\n[temporary-directories]: https://docs.pytest.org/en/latest/tmpdir.html#the-default-base-temporary-directory\n[tox]: https://pypi.org/project/tox/\n[new-issue]: https://github.com/hackebrot/pytest-cookies/issues\n[code-of-conduct]: https://github.com/hackebrot/pytest-cookies/blob/main/CODE_OF_CONDUCT.md\n[community]: https://github.com/hackebrot/pytest-cookies/blob/main/COMMUNITY.md\n[license]: https://github.com/hackebrot/pytest-cookies/blob/main/LICENSE\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The pytest plugin for your Cookiecutter templates. \ud83c\udf6a",
    "version": "0.7.0",
    "project_urls": {
        "Homepage": "https://github.com/hackebrot/pytest-cookies",
        "Issues": "https://github.com/hackebrot/pytest-cookies/issues",
        "Repository": "https://github.com/hackebrot/pytest-cookies"
    },
    "split_keywords": [
        "cookiecutter",
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ff7438af2f3a6c58f81d22c126707ee5d079f653a76961f4fb7d995e526a9c4",
                "md5": "a4b5e172a83a85d02293325bbf941eec",
                "sha256": "52770f090d77b16428f6a24a208e6be76addb2e33458035714087b4de49389ea"
            },
            "downloads": -1,
            "filename": "pytest_cookies-0.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a4b5e172a83a85d02293325bbf941eec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6386,
            "upload_time": "2023-03-22T11:07:28",
            "upload_time_iso_8601": "2023-03-22T11:07:28.068413Z",
            "url": "https://files.pythonhosted.org/packages/5f/f7/438af2f3a6c58f81d22c126707ee5d079f653a76961f4fb7d995e526a9c4/pytest_cookies-0.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "182e11a3e1abb4bbf10e0af3f194ba4c55600de3fe52417ef3594c18d28ecdbe",
                "md5": "3cbc01e9b5dafa1299b85e8660167810",
                "sha256": "1aaa6b4def8238d0d1709d3d773b423351bfb671c1e3438664d824e0859d6308"
            },
            "downloads": -1,
            "filename": "pytest-cookies-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3cbc01e9b5dafa1299b85e8660167810",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8840,
            "upload_time": "2023-03-22T11:07:29",
            "upload_time_iso_8601": "2023-03-22T11:07:29.595862Z",
            "url": "https://files.pythonhosted.org/packages/18/2e/11a3e1abb4bbf10e0af3f194ba4c55600de3fe52417ef3594c18d28ecdbe/pytest-cookies-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-22 11:07:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hackebrot",
    "github_project": "pytest-cookies",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-cookies"
}
        
Elapsed time: 0.24918s