Skip to content
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
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[dependency-groups]
typechecking = [
"pytest",
"pytest-venv",
]

[tool.pytest.ini_options]
Expand Down Expand Up @@ -61,7 +60,6 @@ env_run_base = {commands = [
], deps = [
"cookiecutter",
"pytest",
"pytest-venv",
], description = "Test package creation", skip_install = true}
gh.python = {"3.11" = [
"py311",
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
"""Fixtures for the cookiecutter template tests."""

import os
import pathlib
import subprocess
import typing
import venv

import pytest


@pytest.fixture(scope="function") # noqa: PT003
def temp_venv(tmp_path: pathlib.Path) -> pathlib.Path:
"""Create a temporary isolated virtual environment for tests."""
environment = tmp_path / "venv"
venv.create(environment, with_pip=True)
# Handle Windows environments as an exception that uses Scripts
# instead of bin
return environment / ("Scripts" if os.name == "nt" else "bin")


@pytest.fixture(scope="function") # noqa: PT003
def default_config() -> dict[str, str]:
"""
Expand Down
33 changes: 24 additions & 9 deletions tests/test_package_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import typing

import pytest
import pytest_venv # type: ignore[import-not-found]


def test_package_generation(
Expand Down Expand Up @@ -43,15 +42,15 @@ def test_package_generation(


def test_pip_installable(
venv: pytest_venv.VirtualEnvironment,
generate_package: typing.Callable,
temp_venv: pathlib.Path,
) -> None:
"""Test generated package is pip installable."""
_, test_project_dir = generate_package()
# Try to install package in virtual environment with pip
pipinstall = subprocess.run( # noqa: S603
[
venv.python,
pathlib.Path(temp_venv) / "python",
"-m",
"pip",
"install",
Expand All @@ -67,15 +66,20 @@ def test_pip_installable(


def test_uv_installable(
venv: pytest_venv.VirtualEnvironment,
generate_package: typing.Callable,
temp_venv: pathlib.Path,
) -> None:
"""Test generated package is uv installable."""
_, test_project_dir = generate_package()
venv.install("uv", upgrade=True)
# Try to install uv in the virtual environment
subprocess.run( # noqa: S603
[pathlib.Path(temp_venv) / "python", "-m", "pip", "install", "uv", "--upgrade"],
capture_output=True,
check=False,
)
# Try to install the package in virtual environment with uv
uvsync = subprocess.run( # noqa: S603
[pathlib.Path(venv.bin) / "uv", "sync"],
[pathlib.Path(temp_venv) / "uv", "sync"],
cwd=test_project_dir,
capture_output=True,
check=False,
Expand Down Expand Up @@ -107,15 +111,26 @@ def test_optional_funder(


def test_docs_build(
venv: pytest_venv.VirtualEnvironment,
temp_venv: pathlib.Path,
generate_package: typing.Callable,
) -> None:
"""Test documentation build from package created from template."""
_, test_project_dir = generate_package()
venv.install("tox")
# Tox install
subprocess.run( # noqa: S603
[
pathlib.Path(temp_venv) / "python",
"-m",
"pip",
"install",
"tox",
],
capture_output=True,
check=False,
)
tox_docs_process = subprocess.run( # noqa: S603
[
pathlib.Path(venv.bin) / "tox",
pathlib.Path(temp_venv) / "tox",
"-e",
"docs",
],
Expand Down
Loading