Skip to content

Commit

Permalink
Enforce isolation for cookiecutter tests
Browse files Browse the repository at this point in the history
Create and configure custom, per-test, cookiecutter "cache/storage" dirs
  • Loading branch information
abravalheri committed Jun 6, 2018
1 parent 2b18b04 commit d3d1eb0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/extensions/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import re
import sys
from os import environ
from os.path import exists as path_exists

import pytest
Expand All @@ -17,6 +18,30 @@
COOKIECUTTER_FILES = ["proj/Makefile", "proj/.github/ISSUE_TEMPLATE.md"]


@pytest.fixture(autouse=True)
def cookiecutter_config(tmpfolder):
# Define custom "cache" directories for cookiecutter inside a temporary
# directory per test.
# This way, if the tests are running in parallel, each test has its own
# "cache" and stores/removes cookiecutter templates in an isolated way
# avoiding inconsistencies/race conditions.
config = (
'cookiecutters_dir: "{dir}/custom-cookiecutters"\n'
'replay_dir: "{dir}/cookiecutters-replay"'
).format(dir=str(tmpfolder))

tmpfolder.mkdir('custom-cookiecutters')
tmpfolder.mkdir('cookiecutters-replay')

config_file = tmpfolder.join('cookiecutter.yaml')
config_file.write(config)
environ['COOKIECUTTER_CONFIG'] = str(config_file)

yield

del environ['COOKIECUTTER_CONFIG']


@pytest.mark.slow
def test_create_project_with_cookiecutter(tmpfolder):
# Given options with the cookiecutter extension,
Expand Down

0 comments on commit d3d1eb0

Please sign in to comment.