diff --git a/pyproject.toml b/pyproject.toml index 34e421c22..54326ad18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -179,8 +179,8 @@ omit = [ ] [tool.coverage.paths] -hatch = ["src", "*/hatch/src"] -hatchling = ["backend/src", "*/hatch/backend/src"] +hatch = ["src/hatch", "*/hatch/src/hatch"] +hatchling = ["backend/src/hatchling", "*/hatch/backend/src/hatchling"] tests = ["tests", "*/hatch/tests"] [tool.coverage.report] diff --git a/src/hatch/template/files_default.py b/src/hatch/template/files_default.py index 772e546a0..6ebc985b5 100644 --- a/src/hatch/template/files_default.py +++ b/src/hatch/template/files_default.py @@ -136,10 +136,20 @@ def __init__(self, template_config: dict, plugin_config: dict): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -192,7 +202,26 @@ def __init__(self, template_config: dict, plugin_config: dict): ] [tool.ruff.isort] -known-first-party = ["{template_config['package_name']}"]""" +known-first-party = ["{template_config['package_name']}"] + +[tool.coverage.run] +source_pkgs = ["{template_config['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "{package_location}{template_config['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{template_config['package_name']} = ["{package_location}{template_config['package_name']}", "*/{template_config['project_name_normalized']}/{package_location}{template_config['package_name']}"] +tests = ["tests", "*/{template_config['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +]""" # noqa: E501 super().__init__( Path('pyproject.toml'), diff --git a/tests/helpers/templates/new/default.py b/tests/helpers/templates/new/default.py index fb4b7d3ad..5dbf32999 100644 --- a/tests/helpers/templates/new/default.py +++ b/tests/helpers/templates/new/default.py @@ -106,10 +106,20 @@ def get_files(**kwargs): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -163,6 +173,25 @@ def get_files(**kwargs): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "src/{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ] diff --git a/tests/helpers/templates/new/feature_cli.py b/tests/helpers/templates/new/feature_cli.py index f87c634bf..6e6ad88c8 100644 --- a/tests/helpers/templates/new/feature_cli.py +++ b/tests/helpers/templates/new/feature_cli.py @@ -141,10 +141,20 @@ def {kwargs['package_name']}(ctx: click.Context): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -198,6 +208,25 @@ def {kwargs['package_name']}(ctx: click.Context): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "src/{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ] diff --git a/tests/helpers/templates/new/feature_no_src_layout.py b/tests/helpers/templates/new/feature_no_src_layout.py index dd859868b..82a0fe29c 100644 --- a/tests/helpers/templates/new/feature_no_src_layout.py +++ b/tests/helpers/templates/new/feature_no_src_layout.py @@ -106,10 +106,20 @@ def get_files(**kwargs): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -163,6 +173,25 @@ def get_files(**kwargs): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ] diff --git a/tests/helpers/templates/new/licenses_empty.py b/tests/helpers/templates/new/licenses_empty.py index 919ff23bd..f07599b00 100644 --- a/tests/helpers/templates/new/licenses_empty.py +++ b/tests/helpers/templates/new/licenses_empty.py @@ -69,10 +69,20 @@ def get_files(**kwargs): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -126,6 +136,25 @@ def get_files(**kwargs): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "src/{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ] diff --git a/tests/helpers/templates/new/licenses_multiple.py b/tests/helpers/templates/new/licenses_multiple.py index 682ade858..e77a4471b 100644 --- a/tests/helpers/templates/new/licenses_multiple.py +++ b/tests/helpers/templates/new/licenses_multiple.py @@ -109,10 +109,20 @@ def get_files(**kwargs): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -166,6 +176,25 @@ def get_files(**kwargs): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "src/{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ] diff --git a/tests/helpers/templates/new/projects_urls_empty.py b/tests/helpers/templates/new/projects_urls_empty.py index 308526199..e2c430b86 100644 --- a/tests/helpers/templates/new/projects_urls_empty.py +++ b/tests/helpers/templates/new/projects_urls_empty.py @@ -101,10 +101,20 @@ def get_files(**kwargs): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -158,6 +168,25 @@ def get_files(**kwargs): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "src/{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ] diff --git a/tests/helpers/templates/new/projects_urls_space_in_label.py b/tests/helpers/templates/new/projects_urls_space_in_label.py index fcbea1654..710defd10 100644 --- a/tests/helpers/templates/new/projects_urls_space_in_label.py +++ b/tests/helpers/templates/new/projects_urls_space_in_label.py @@ -104,10 +104,20 @@ def get_files(**kwargs): [tool.hatch.envs.default] dependencies = [ + "coverage[toml]>=6.5", "pytest", ] [tool.hatch.envs.default.scripts] test = "pytest {{args:tests}}" +test-cov = "coverage run -m pytest {{args:tests}}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", +] [[tool.hatch.envs.all.matrix]] python = ["3.7", "3.8", "3.9", "3.10", "3.11"] @@ -161,6 +171,25 @@ def get_files(**kwargs): [tool.ruff.isort] known-first-party = ["{kwargs['package_name']}"] -""", + +[tool.coverage.run] +source_pkgs = ["{kwargs['package_name']}", "tests"] +branch = true +parallel = true +omit = [ + "src/{kwargs['package_name']}/__about__.py", +] + +[tool.coverage.paths] +{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"] +tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] +""", # noqa: E501 ), ]