core-tests 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: core-tests
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: It contains common elements for testing purposes...
5
5
  Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
6
6
  Maintainer: Alejandro Cora González
@@ -31,7 +31,7 @@ Requires-Dist: click>=8.1.8
31
31
  Requires-Dist: coverage>=7.7.1
32
32
  Requires-Dist: environs>=14.1.1
33
33
  Provides-Extra: dev
34
- Requires-Dist: core-dev-tools>=2.0.0; extra == "dev"
34
+ Requires-Dist: core-dev-tools>=2.1.0; extra == "dev"
35
35
  Dynamic: license-file
36
36
 
37
37
  core-tests
@@ -52,6 +52,10 @@ case than routing it through this abstraction layer.
52
52
 
53
53
  ===============================================================================
54
54
 
55
+ .. image:: https://static.pepy.tech/personalized-badge/core-tests?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads
56
+ :target: https://pepy.tech/projects/core-tests
57
+ :alt: PyPI Downloads
58
+
55
59
  .. image:: https://img.shields.io/pypi/pyversions/core-tests.svg
56
60
  :target: https://pypi.org/project/core-tests/
57
61
  :alt: Python Versions
@@ -100,6 +104,11 @@ Features
100
104
 
101
105
  * **Custom Pattern Support**: Override discovery with ``--pattern`` for
102
106
  non-standard file layouts.
107
+ * **Enforced Coverage**: ``run-coverage`` applies the ``fail_under`` setting of
108
+ your coverage configuration, or ``--fail-under`` for a single run, and exits
109
+ non-zero when the total is below it.
110
+ * **CI-ready Reports**: Writes ``coverage.xml`` (Cobertura, relative paths)
111
+ beside the HTML report, so a CI platform can annotate a merge request diff.
103
112
  * **Test Organization**: Target specific test directories (unit, integration,
104
113
  functional, etc.) via ``--test-type``.
105
114
  * **Branch Coverage Reports**: Generate branch-level coverage reports and
@@ -176,8 +185,11 @@ Generate code coverage reports across all test directories:
176
185
 
177
186
  **Options:**
178
187
 
179
- * ``--save-report``: Save HTML and data coverage reports to disk.
188
+ * ``--save-report``: Save HTML, XML and data coverage reports to disk.
180
189
  Default: ``True``
190
+ * ``--fail-under``: Minimum total coverage percentage. Exits non-zero below it,
191
+ and takes precedence over the ``fail_under`` setting of the coverage
192
+ configuration. Default: unset, so the configured value applies.
181
193
 
182
194
  **Examples:**
183
195
 
@@ -185,6 +197,11 @@ Generate code coverage reports across all test directories:
185
197
 
186
198
  python manager.py run-coverage
187
199
  python manager.py run-coverage --save-report false
200
+ python manager.py run-coverage --fail-under 90
201
+
202
+ The HTML report lands in ``htmlcov/``, and a Cobertura ``coverage.xml`` beside
203
+ it, with paths relative to the working directory so a CI platform can map them
204
+ onto the repository.
188
205
 
189
206
 
190
207
  Quick Start
@@ -16,6 +16,10 @@ case than routing it through this abstraction layer.
16
16
 
17
17
  ===============================================================================
18
18
 
19
+ .. image:: https://static.pepy.tech/personalized-badge/core-tests?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads
20
+ :target: https://pepy.tech/projects/core-tests
21
+ :alt: PyPI Downloads
22
+
19
23
  .. image:: https://img.shields.io/pypi/pyversions/core-tests.svg
20
24
  :target: https://pypi.org/project/core-tests/
21
25
  :alt: Python Versions
@@ -64,6 +68,11 @@ Features
64
68
 
65
69
  * **Custom Pattern Support**: Override discovery with ``--pattern`` for
66
70
  non-standard file layouts.
71
+ * **Enforced Coverage**: ``run-coverage`` applies the ``fail_under`` setting of
72
+ your coverage configuration, or ``--fail-under`` for a single run, and exits
73
+ non-zero when the total is below it.
74
+ * **CI-ready Reports**: Writes ``coverage.xml`` (Cobertura, relative paths)
75
+ beside the HTML report, so a CI platform can annotate a merge request diff.
67
76
  * **Test Organization**: Target specific test directories (unit, integration,
68
77
  functional, etc.) via ``--test-type``.
69
78
  * **Branch Coverage Reports**: Generate branch-level coverage reports and
@@ -140,8 +149,11 @@ Generate code coverage reports across all test directories:
140
149
 
141
150
  **Options:**
142
151
 
143
- * ``--save-report``: Save HTML and data coverage reports to disk.
152
+ * ``--save-report``: Save HTML, XML and data coverage reports to disk.
144
153
  Default: ``True``
154
+ * ``--fail-under``: Minimum total coverage percentage. Exits non-zero below it,
155
+ and takes precedence over the ``fail_under`` setting of the coverage
156
+ configuration. Default: unset, so the configured value applies.
145
157
 
146
158
  **Examples:**
147
159
 
@@ -149,6 +161,11 @@ Generate code coverage reports across all test directories:
149
161
 
150
162
  python manager.py run-coverage
151
163
  python manager.py run-coverage --save-report false
164
+ python manager.py run-coverage --fail-under 90
165
+
166
+ The HTML report lands in ``htmlcov/``, and a Cobertura ``coverage.xml`` beside
167
+ it, with paths relative to the working directory so a CI platform can map them
168
+ onto the repository.
152
169
 
153
170
 
154
171
  Quick Start
@@ -1,11 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  """
4
2
  Provides common elements for testing purposes.
5
3
  """
6
4
 
7
- from importlib.metadata import PackageNotFoundError
8
- from importlib.metadata import version
5
+ from importlib.metadata import PackageNotFoundError, version
9
6
 
10
7
  from core_tests.tests.base import BaseTestCase
11
8
  from core_tests.tests.runner import cli_tests
@@ -18,7 +15,7 @@ except PackageNotFoundError:
18
15
 
19
16
 
20
17
  __all__ = [
21
- "__version__",
22
18
  "BaseTestCase",
19
+ "__version__",
23
20
  "cli_tests",
24
21
  ]
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  """
4
2
  It's just the base class should be used for all
5
3
  test cases unittest-based within the code
@@ -7,7 +5,6 @@ ecosystem.
7
5
  """
8
6
 
9
7
  import os
10
-
11
8
  from unittest import TestCase
12
9
 
13
10
 
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  """
4
2
  This module provides a group of CLI commands that abstract unittest-based
5
3
  test execution and code coverage measurement. Consuming projects import
@@ -28,6 +26,7 @@ picked up automatically.
28
26
  * ``python manager.py run-tests --test-type integration``
29
27
  * ``python manager.py run-tests --test-type functional --pattern "*.py"``
30
28
  * ``python manager.py run-coverage``
29
+ * ``python manager.py run-coverage --fail-under 90``
31
30
  """
32
31
 
33
32
  from __future__ import annotations
@@ -35,15 +34,11 @@ from __future__ import annotations
35
34
  import logging
36
35
  import os
37
36
  import sys
38
- import typing
39
- from unittest import TestCase
40
- from unittest import TestLoader
41
- from unittest import TestSuite
42
- from unittest import TextTestRunner
37
+ from unittest import TestCase, TestLoader, TestSuite, TextTestRunner
43
38
 
44
39
  from click import echo, option
45
40
  from click.decorators import group
46
- from coverage import coverage, CoverageException
41
+ from coverage import CoverageException, coverage
47
42
 
48
43
  patterns = [
49
44
  "test_*.py",
@@ -85,7 +80,7 @@ def run_tests(test_type: str, pattern: str) -> None:
85
80
  level = os.getenv("LOGGER_LEVEL_FOR_TEST", str(logging.ERROR))
86
81
  os.environ["LOGGER_LEVEL"] = level
87
82
 
88
- all_tests: typing.List[TestCase | TestSuite] = []
83
+ all_tests: list[TestCase | TestSuite] = []
89
84
 
90
85
  if pattern != "tests_*.py":
91
86
  tests = TestLoader().discover(f"./tests/{test_type}", pattern=pattern)
@@ -103,18 +98,32 @@ def run_tests(test_type: str, pattern: str) -> None:
103
98
 
104
99
  @cli_tests.command("run-coverage")
105
100
  @option("-s", "--save-report", "save_report", default=True)
106
- def run_coverage(save_report: bool) -> None:
101
+ @option(
102
+ "-f",
103
+ "--fail-under",
104
+ "fail_under",
105
+ type=float,
106
+ default=None,
107
+ help="Minimum total coverage percentage. Overrides 'fail_under' of the coverage configuration.",
108
+ )
109
+ def run_coverage(save_report: bool, fail_under: float | None) -> None:
107
110
  """
108
111
  Runs all tests across all test directories and generates a coverage report.
109
112
 
110
- :param save_report: Whether to save HTML and data coverage reports to disk.
113
+ :param save_report: Whether to save HTML, XML and data coverage reports to disk.
111
114
  :type save_report: bool
112
115
 
116
+ :param fail_under: Minimum total coverage percentage. Takes precedence over the
117
+ ``fail_under`` setting of the coverage configuration. The command exits
118
+ non-zero when the measured total is below it.
119
+ :type fail_under: float | None
120
+
113
121
  Coverage Analysis:
114
122
  - Runs tests with branch coverage enabled.
115
123
  - Analyzes all source files in current directory.
116
124
  - Generates console report summary.
117
- - Optionally saves HTML report (default: True).
125
+ - Optionally saves HTML and XML reports (default: True).
126
+ - Enforces a minimum total coverage when one is configured.
118
127
 
119
128
  File Discovery:
120
129
  Automatically finds files matching: ``test_*.py``, ``*_test.py``, ``tests_*.py``
@@ -125,9 +134,14 @@ def run_coverage(save_report: bool) -> None:
125
134
 
126
135
  os.environ["LOGGER_LEVEL"] = os.getenv("LOGGER_LEVEL_FOR_TEST", str(logging.ERROR))
127
136
  coverage_ = coverage(branch=True, source=["."])
137
+
138
+ # Record paths relative to the working directory. Tools that consume the
139
+ # XML report, such as the merge request annotations of a CI platform,
140
+ # cannot map the absolute paths of a container onto the repository.
141
+ coverage_.config.relative_files = True
128
142
  coverage_.start()
129
143
 
130
- all_tests: typing.List[TestCase | TestSuite] = []
144
+ all_tests: list[TestCase | TestSuite] = []
131
145
  for pattern_glob in patterns:
132
146
  tests = TestLoader().discover("./tests", pattern=pattern_glob)
133
147
  all_tests.extend(tests)
@@ -140,14 +154,22 @@ def run_coverage(save_report: bool) -> None:
140
154
 
141
155
  try:
142
156
  echo("Coverage Summary:")
143
- coverage_.report()
157
+ total = coverage_.report()
144
158
 
145
159
  if save_report:
146
160
  coverage_.save()
147
161
  coverage_.html_report()
162
+ coverage_.xml_report()
148
163
 
149
164
  coverage_.erase()
150
165
 
151
166
  except CoverageException as error:
152
167
  echo(error)
153
168
  sys.exit(1)
169
+
170
+ # 'fail_under' of the coverage configuration is enforced by the 'coverage'
171
+ # command line, not by the API used here, so it is applied explicitly.
172
+ threshold = fail_under if fail_under is not None else coverage_.config.fail_under
173
+ if threshold and total < threshold:
174
+ echo(f"Coverage {total:.2f}% is below the required {threshold}%.")
175
+ sys.exit(1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: core-tests
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: It contains common elements for testing purposes...
5
5
  Author-email: Alejandro Cora González <alek.cora.glez@gmail.com>
6
6
  Maintainer: Alejandro Cora González
@@ -31,7 +31,7 @@ Requires-Dist: click>=8.1.8
31
31
  Requires-Dist: coverage>=7.7.1
32
32
  Requires-Dist: environs>=14.1.1
33
33
  Provides-Extra: dev
34
- Requires-Dist: core-dev-tools>=2.0.0; extra == "dev"
34
+ Requires-Dist: core-dev-tools>=2.1.0; extra == "dev"
35
35
  Dynamic: license-file
36
36
 
37
37
  core-tests
@@ -52,6 +52,10 @@ case than routing it through this abstraction layer.
52
52
 
53
53
  ===============================================================================
54
54
 
55
+ .. image:: https://static.pepy.tech/personalized-badge/core-tests?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads
56
+ :target: https://pepy.tech/projects/core-tests
57
+ :alt: PyPI Downloads
58
+
55
59
  .. image:: https://img.shields.io/pypi/pyversions/core-tests.svg
56
60
  :target: https://pypi.org/project/core-tests/
57
61
  :alt: Python Versions
@@ -100,6 +104,11 @@ Features
100
104
 
101
105
  * **Custom Pattern Support**: Override discovery with ``--pattern`` for
102
106
  non-standard file layouts.
107
+ * **Enforced Coverage**: ``run-coverage`` applies the ``fail_under`` setting of
108
+ your coverage configuration, or ``--fail-under`` for a single run, and exits
109
+ non-zero when the total is below it.
110
+ * **CI-ready Reports**: Writes ``coverage.xml`` (Cobertura, relative paths)
111
+ beside the HTML report, so a CI platform can annotate a merge request diff.
103
112
  * **Test Organization**: Target specific test directories (unit, integration,
104
113
  functional, etc.) via ``--test-type``.
105
114
  * **Branch Coverage Reports**: Generate branch-level coverage reports and
@@ -176,8 +185,11 @@ Generate code coverage reports across all test directories:
176
185
 
177
186
  **Options:**
178
187
 
179
- * ``--save-report``: Save HTML and data coverage reports to disk.
188
+ * ``--save-report``: Save HTML, XML and data coverage reports to disk.
180
189
  Default: ``True``
190
+ * ``--fail-under``: Minimum total coverage percentage. Exits non-zero below it,
191
+ and takes precedence over the ``fail_under`` setting of the coverage
192
+ configuration. Default: unset, so the configured value applies.
181
193
 
182
194
  **Examples:**
183
195
 
@@ -185,6 +197,11 @@ Generate code coverage reports across all test directories:
185
197
 
186
198
  python manager.py run-coverage
187
199
  python manager.py run-coverage --save-report false
200
+ python manager.py run-coverage --fail-under 90
201
+
202
+ The HTML report lands in ``htmlcov/``, and a Cobertura ``coverage.xml`` beside
203
+ it, with paths relative to the working directory so a CI platform can map them
204
+ onto the repository.
188
205
 
189
206
 
190
207
  Quick Start
@@ -3,4 +3,4 @@ coverage>=7.7.1
3
3
  environs>=14.1.1
4
4
 
5
5
  [dev]
6
- core-dev-tools>=2.0.0
6
+ core-dev-tools>=2.1.0
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
8
8
 
9
9
  [project]
10
10
  name = "core-tests"
11
- version = "2.1.0"
11
+ version = "2.2.0"
12
12
 
13
13
  description = """It contains common elements for testing purposes..."""
14
14
 
@@ -50,7 +50,7 @@ dependencies = [
50
50
 
51
51
  [project.optional-dependencies]
52
52
  dev = [
53
- "core-dev-tools>=2.0.0",
53
+ "core-dev-tools>=2.1.0",
54
54
  ]
55
55
 
56
56
  [project.urls]
File without changes
File without changes
File without changes