Skip to content

Enable test for creating an environment. #2

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

Merged
merged 10 commits into from
Jan 5, 2022
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
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ This is a record of all past cookiecutter-pytask releases and what went into the
reverse chronological order.


1.0.0 - 2021-12-22
1.0.0 - 2021-01-05
------------------

- :gh:`1` creates first release of a minimal cookiecutter template for a pytask project.
- :gh:`2` adds more tests.
5 changes: 3 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def main():
if "{{ cookiecutter.add_readthedocs }}" == "no":
remove_file(project_path, ".readthedocs.yaml")

subprocess.run(("git", "init"), check=True, capture_output=True)

if "{{ cookiecutter.make_initial_commit }}" == "yes":
# Create an initial commit on the main branch and restore global default name.
p = subprocess.run(
Expand All @@ -51,7 +53,6 @@ def main():
subprocess.run(
("git", "config", "--global", "init.defaultBranch", "main"), check=True
)
subprocess.run(("git", "init"), check=True, capture_output=True)
subprocess.run(
("git", "config", "user.name", "'{{ cookiecutter.github_username }}'"),
check=True,
Expand Down Expand Up @@ -83,7 +84,7 @@ def main():
"executable was found."
)
else:
subprocess.run(("conda", "env", "create"), check=True)
subprocess.run((conda_exe, "env", "create"), check=True)


if __name__ == "__main__":
Expand Down
23 changes: 14 additions & 9 deletions tests/test_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ def test_remove_changes(cookies):


@pytest.mark.end_to_end
@pytest.mark.skipif(
os.environ.get("CI", "false") == "false",
reason="Conda environment is only created on CI service.",
)
@pytest.mark.skipif(os.environ.get("CI") is None, reason="Run only in CI.")
def test_check_conda_environment_creation_and_run_all_checks(cookies):
"""Test that the conda environment is created and pre-commit passes."""
result = cookies.bake(
Expand All @@ -103,8 +100,16 @@ def test_check_conda_environment_creation_and_run_all_checks(cookies):
assert result.exit_code == 0
assert result.exception is None

subprocess.run(
("conda", "run", "-n", "__test__", "pre-commit", "run", "--all-files"),
cwd=result.project_path,
check=True,
)
if sys.platform != "win32":
# Switch branch before pre-commit because otherwise failure because on main
# branch.
subprocess.run(
("git", "checkout", "-b", "test"), cwd=result.project_path, check=True
)

# Do not check exit code on Windows since something weird happens.
subprocess.run(
("conda", "run", "-n", "__test__", "pre-commit", "run", "--all-files"),
cwd=result.project_path,
check=True,
)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ whitelist_externals = python

[testenv]
basepython = python
passenv = CI

[testenv:pytest]
conda_channels =
Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dependencies:
- setuptools_scm
- toml

# Reproducibility
- conda-lock

# Package dependencies
- pytask

Expand Down