noirbizarre / pytest-copier

A Copier plugin for pytest to help testing Copier templates
MIT License
9 stars 1 forks source link

is there a documentation somewhere ? #3

Open 12rambau opened 1 year ago

12rambau commented 1 year ago

I'm moving from cookiecutter to copier for my template and one thing I'm missing is a copier pytest plugin that I could use to check my templates are actually working as expected.

I'm looking for something like https://github.com/hackebrot/pytest-cookies and it seems your lib could do the job !

simone-gaiarin commented 1 year ago

I agree it would be nice to have a documentation or a few examples.

In the meanwhile try to read the code here, it's not that difficult.

Example of how I used it:

@pytest.fixture
def required_answers():
    return {
        "author_email": "user@example.com",
        "author_name": "The User",
        "project_name": "Python Boilerplate",
    }

def test_bake_with_defaults(copier, required_answers):
    project = copier.copy(**required_answers)

    found_toplevel_files = [f.name for f in project.path.glob("*")]

    assert ".gitignore" in found_toplevel_files
    assert "pyproject.toml" in found_toplevel_files

def test_bake_and_run_tests_with_pytest_framework(copier, required_answers):
    custom_answers = {"testing_framework": "pytest"}
    answers = {**required_answers, **custom_answers}
    project = copier.copy(**answers)

    project.run("pytest")  

Use project.run with care. pytest must be installed in the system. Running project.run("poetry install") is not a good idea if you are already working in a virtual env.

simone-gaiarin commented 1 year ago

Even better, by overriding pytest-copier dummy fixtures:

@pytest.fixture
def copier_defaults():
    return {
        "author_email": "user@example.com",
        "author_name": "The User",
        "project_name": "Python Boilerplate",
    }

def test_bake_with_defaults(copier):
    project = copier.copy()

    found_toplevel_files = [f.name for f in project.path.glob("*")]

    assert ".gitignore" in found_toplevel_files
    assert "pyproject.toml" in found_toplevel_files

def test_bake_and_run_tests_with_pytest_framework(copier):
    custom_answers = {"testing_framework": "pytest"}
    project = copier.copy(**custom_answers)

    project.run("pytest")  

Other fixture that are possibly overridable: copier_template_paths or copier_template

12rambau commented 1 year ago

Thanks for your answers, unfortunately I ended up writing my own plugin based on the one I was using for cookie-cutter: https://pytest-copie.readthedocs.io/

noirbizarre commented 12 months ago

Sorry, I have not been available lately. Yes, documentation and tests are missing. It was a first release I needed to validate a PoC. Documentation and missing tests should come very soon.

Thanks for the pytest-cookies reference as well as the suggestion I will take into account.

12rambau commented 12 months ago

no problem. As I already coded something from my side would you mind reading my documentation and let me know if things can be integrated either in your lib or alternatively in mine. I would like to avoid splitting the effort and get the best tools in one single lib. I don't know what you think but we could also request to move the merged project to the copier org to give it more visibility.

kenibrewer commented 8 months ago

Hey @noirbizarre and @12rambau, thanks so much for both of your efforts working on this! This is a definitely a needed tool and something that will be super helpful for a modular copier template I'm working on.

I'm interested in contributing some code and / or documentation. It looks like @12rambau is further along with his version, but the name pytest-copier will be way easier for folks to remember. Would it be possible to join forces to move forward with 12rambau's project under the pytest-copier name?

12rambau commented 8 months ago

I have already offered to merge these 2 repositories several month ago for this exact reason, pytest-copier is a way better name but it was already taken by this PoC.

My lib is in production and used by some external projects, mostly projects coming from pytest-cookie, happy to find the same interface when they make the jump between cookiecutter and copier. They already helped me improve its robustness.

I would be happy to discuss about a merge and gather everything under the pytest-copier name but that's entirely @noirbizarre descision.

@kenibrewer if you are still up for contributions and you like my implementation, I can review them in pytest-copie.

simone-gaiarin commented 8 months ago

happy to find the same interface when they make the jump between cookiecutter and copier

I recently switched from cookiecutter to copier and I've previously used pytest-cookies. I must say that I prefer the new interface offered by pytest-copier

Compared to pytest-cookies, it seems that I need to write less code to write the tests and that the result is cleaner.

I agree that the best outcome would be to join the forces to work on a single project, but on the other hand I support the new interface provided by pytest-copier even though it is not compatible with pytest-cookies.

kenibrewer commented 8 months ago

This conversation has gone a bit beyond the original issue (a request for documentation). I created a separate issue to move the conversation about the merge.

9

noirbizarre commented 8 months ago

Hi everyone 👋🏼

There are some answers in #10

For the documentation part, I am sorry for the lack of it. It will come soon but as I said, it was at first a quick and dirty (successful) experimentation which are are currently using daily.

We are reaching the point where, after the last refactorings and the last feature (snapshotting) lands, docs and tests will come. I am still interested into giving the project to the community, ideally to @copier-org for consistency.

I'll try to provide a simple exemple tonight or tomorrow (as I can't copy-paste those form my work)

kenibrewer commented 8 months ago

@12rambau Would you like to comment in discussion #10 ? I'm not sure if you got the notification of me tagging you there since you aren't a participant

12rambau commented 8 months ago

let me finish my workday and I'll provide a detailed answer