Skip to content

Commit 37afa4c

Browse files
authored
Enable test for creating an environment. (#2)
1 parent 02506ad commit 37afa4c

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

CHANGES.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ This is a record of all past cookiecutter-pytask releases and what went into the
55
reverse chronological order.
66

77

8-
1.0.0 - 2021-12-22
8+
1.0.0 - 2021-01-05
99
------------------
1010

1111
- :gh:`1` creates first release of a minimal cookiecutter template for a pytask project.
12+
- :gh:`2` adds more tests.

hooks/post_gen_project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def main():
4242
if "{{ cookiecutter.add_readthedocs }}" == "no":
4343
remove_file(project_path, ".readthedocs.yaml")
4444

45+
subprocess.run(("git", "init"), check=True, capture_output=True)
46+
4547
if "{{ cookiecutter.make_initial_commit }}" == "yes":
4648
# Create an initial commit on the main branch and restore global default name.
4749
p = subprocess.run(
@@ -51,7 +53,6 @@ def main():
5153
subprocess.run(
5254
("git", "config", "--global", "init.defaultBranch", "main"), check=True
5355
)
54-
subprocess.run(("git", "init"), check=True, capture_output=True)
5556
subprocess.run(
5657
("git", "config", "user.name", "'{{ cookiecutter.github_username }}'"),
5758
check=True,
@@ -83,7 +84,7 @@ def main():
8384
"executable was found."
8485
)
8586
else:
86-
subprocess.run(("conda", "env", "create"), check=True)
87+
subprocess.run((conda_exe, "env", "create"), check=True)
8788

8889

8990
if __name__ == "__main__":

tests/test_cookie.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ def test_remove_changes(cookies):
8787

8888

8989
@pytest.mark.end_to_end
90-
@pytest.mark.skipif(
91-
os.environ.get("CI", "false") == "false",
92-
reason="Conda environment is only created on CI service.",
93-
)
90+
@pytest.mark.skipif(os.environ.get("CI") is None, reason="Run only in CI.")
9491
def test_check_conda_environment_creation_and_run_all_checks(cookies):
9592
"""Test that the conda environment is created and pre-commit passes."""
9693
result = cookies.bake(
@@ -103,8 +100,16 @@ def test_check_conda_environment_creation_and_run_all_checks(cookies):
103100
assert result.exit_code == 0
104101
assert result.exception is None
105102

106-
subprocess.run(
107-
("conda", "run", "-n", "__test__", "pre-commit", "run", "--all-files"),
108-
cwd=result.project_path,
109-
check=True,
110-
)
103+
if sys.platform != "win32":
104+
# Switch branch before pre-commit because otherwise failure because on main
105+
# branch.
106+
subprocess.run(
107+
("git", "checkout", "-b", "test"), cwd=result.project_path, check=True
108+
)
109+
110+
# Do not check exit code on Windows since something weird happens.
111+
subprocess.run(
112+
("conda", "run", "-n", "__test__", "pre-commit", "run", "--all-files"),
113+
cwd=result.project_path,
114+
check=True,
115+
)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ whitelist_externals = python
66

77
[testenv]
88
basepython = python
9+
passenv = CI
910

1011
[testenv:pytest]
1112
conda_channels =

{{cookiecutter.project_slug}}/environment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ dependencies:
1010
- setuptools_scm
1111
- toml
1212

13+
# Reproducibility
14+
- conda-lock
15+
1316
# Package dependencies
1417
- pytask
1518

0 commit comments

Comments
 (0)