diff --git a/CHANGES.rst b/CHANGES.rst index 3e53706..5cf707e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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. diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index e9cf9bf..a75e87c 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -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( @@ -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, @@ -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__": diff --git a/tests/test_cookie.py b/tests/test_cookie.py index 464b64c..f6d22f0 100644 --- a/tests/test_cookie.py +++ b/tests/test_cookie.py @@ -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( @@ -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, + ) diff --git a/tox.ini b/tox.ini index 64492f2..f8f549f 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ whitelist_externals = python [testenv] basepython = python +passenv = CI [testenv:pytest] conda_channels = diff --git a/{{cookiecutter.project_slug}}/environment.yml b/{{cookiecutter.project_slug}}/environment.yml index 6b837d6..3f4a743 100644 --- a/{{cookiecutter.project_slug}}/environment.yml +++ b/{{cookiecutter.project_slug}}/environment.yml @@ -10,6 +10,9 @@ dependencies: - setuptools_scm - toml + # Reproducibility + - conda-lock + # Package dependencies - pytask