Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(test): move baking to a common fixture #373

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
"""Pytest configuration."""

import pytest
import sh

from .bake import bake_in_temp_dir

# Pytest will rewrite assertions in test modules, but not elsewhere.
# This tells pytest to also rewrite assertions in these modules.
pytest.register_assert_rewrite("tests.common_tests")


@pytest.fixture(name="custom_template", scope="module")
def fixture_custom_template(cookies_session, custom_template_name):
"""
Produce the template directory to use with tests.

Each test_cookiecutter_*.py file uses a different cookiecutter directory.
It gives the base name with the `custom_template_name` fixture. This makes
a full path for use with `bake_in_temp_dir`.
"""
template = cookies_session._default_template + "/" + custom_template_name # pylint: disable=protected-access
return template


@pytest.fixture(scope="module")
def options_baked(cookies_session, configuration, custom_template):
"""
Bake a cookie cutter, parameterized by configurations.

Provides the configuration dict, and changes into the directory with the
baked result.
"""
with bake_in_temp_dir(cookies_session, extra_context=configuration, template=custom_template):
sh.make('upgrade')
sh.pip('install', '-r', 'requirements/test.txt')
yield configuration
23 changes: 6 additions & 17 deletions tests/test_cookiecutter_django_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,14 @@
]


@pytest.fixture(name='custom_template', scope="module")
def fixture_custom_template(cookies_session):
template = cookies_session._default_template + "/cookiecutter-django-app" # pylint: disable=protected-access
return template
@pytest.fixture(name="configuration", params=configurations, scope="module")
def fixture_configuration(request):
return request.param


@pytest.fixture(params=configurations, name='options_baked', scope="module")
def fixture_options_baked(cookies_session, request, custom_template):
"""
Bake a cookie cutter, parameterized by configurations.

Provides the configuration dict, and changes into the directory with the
baked result.
"""
with bake_in_temp_dir(cookies_session, extra_context=request.param, template=custom_template):
sh.make('upgrade')
sh.pip('install', '-r', 'requirements/test.txt')

yield request.param
@pytest.fixture(name="custom_template_name", scope="module")
def fixture_custom_template_name():
return "cookiecutter-django-app"


# Fixture names aren't always used in test functions. Disable completely.
Expand Down
23 changes: 6 additions & 17 deletions tests/test_cookiecutter_django_ida.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,14 @@
]


@pytest.fixture(name='custom_template', scope="module")
def fixture_custom_template(cookies_session):
template = cookies_session._default_template + "/cookiecutter-django-ida" # pylint: disable=protected-access
return template
@pytest.fixture(name="configuration", params=configurations, scope="module")
def fixture_configuration(request):
return request.param


@pytest.fixture(params=configurations, name='options_baked', scope="module")
def fixture_options_baked(cookies_session, request, custom_template):
"""
Bake a cookie cutter, parameterized by configurations.

Provides the configuration dict, and changes into the directory with the
baked result.
"""
with bake_in_temp_dir(cookies_session, extra_context=request.param, template=custom_template):
sh.make('upgrade')
sh.pip('install', '-r', 'requirements/test.txt')

yield request.param
@pytest.fixture(name="custom_template_name", scope="module")
def fixture_custom_template_name():
return "cookiecutter-django-ida"


# Fixture names aren't always used in test functions. Disable completely.
Expand Down
23 changes: 6 additions & 17 deletions tests/test_cookiecutter_python_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,14 @@
]


@pytest.fixture(name='custom_template', scope="module")
def fixture_custom_template(cookies_session):
template = cookies_session._default_template + "/cookiecutter-python-library" # pylint: disable=protected-access
return template
@pytest.fixture(name="configuration", params=configurations, scope="module")
def fixture_configuration(request):
return request.param


@pytest.fixture(params=configurations, name='options_baked', scope="module")
def fixture_options_baked(cookies_session, request, custom_template):
"""
Bake a cookie cutter, parameterized by configurations.

Provides the configuration dict, and changes into the directory with the
baked result.
"""
with bake_in_temp_dir(cookies_session, extra_context=request.param, template=custom_template):
sh.make('upgrade')
sh.pip('install', '-r', 'requirements/test.txt')

yield request.param
@pytest.fixture(name="custom_template_name", scope="module")
def fixture_custom_template_name():
return "cookiecutter-python-library"


# Fixture names aren't always used in test functions. Disable completely.
Expand Down
26 changes: 8 additions & 18 deletions tests/test_cookiecutter_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,14 @@
]


@pytest.fixture(name='custom_template', scope="module")
def fixture_custom_template(cookies_session):
template = cookies_session._default_template + "/cookiecutter-xblock" # pylint: disable=protected-access
return template


@pytest.fixture(params=configurations, name='options_baked', scope="module")
def fixture_options_baked(cookies_session, request, custom_template):
"""
Bake a cookie cutter, parameterized by configurations.

Provides the configuration dict, and changes into the directory with the
baked result.
"""
with bake_in_temp_dir(cookies_session, extra_context=request.param, template=custom_template):
sh.make('upgrade')
sh.pip('install', '-r', 'requirements/test.txt')
yield request.param
@pytest.fixture(name="configuration", params=configurations, scope="module")
def fixture_configuration(request):
return request.param


@pytest.fixture(name="custom_template_name", scope="module")
def fixture_custom_template_name():
return "cookiecutter-xblock"


# Fixture names aren't always used in test functions. Disable completely.
Expand Down