diff --git a/src/pytest_cookies/plugin.py b/src/pytest_cookies/plugin.py index 6e077c5..738da0b 100644 --- a/src/pytest_cookies/plugin.py +++ b/src/pytest_cookies/plugin.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import json import os import pathlib import warnings @@ -10,11 +11,6 @@ from cookiecutter.main import cookiecutter from cookiecutter.prompt import prompt_for_config -USER_CONFIG = u""" -cookiecutters_dir: "{cookiecutters_dir}" -replay_dir: "{replay_dir}" -""" - class Result(object): """Holds the captured result of the cookiecutter project generation.""" @@ -122,16 +118,17 @@ def bake(self, extra_context=None, template=None): @pytest.fixture(scope="session") def _cookiecutter_config_file(tmpdir_factory): user_dir = tmpdir_factory.mktemp("user_dir") + config_file = user_dir.join("config") - cookiecutters_dir = user_dir.mkdir("cookiecutters") - replay_dir = user_dir.mkdir("cookiecutter_replay") + config = { + "cookiecutters_dir": str(user_dir.mkdir("cookiecutters")), + "replay_dir": str(user_dir.mkdir("cookiecutter_replay")), + } - config_text = USER_CONFIG.format( - cookiecutters_dir=cookiecutters_dir, replay_dir=replay_dir - ) - config_file = user_dir.join("config") + # Note that the file is expected to be YAML, but JSON is a subset of YAML + with config_file.open("w", encoding="utf-8") as f: + json.dump(config, f, indent=2) - config_file.write_text(config_text, encoding="utf8") return config_file