core-tests 2.0.5__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.
- {core_tests-2.0.5 → core_tests-2.2.0}/PKG-INFO +77 -93
- {core_tests-2.0.5 → core_tests-2.2.0}/README.rst +75 -90
- core_tests-2.2.0/core_tests/__init__.py +21 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/core_tests/tests/base.py +0 -3
- core_tests-2.2.0/core_tests/tests/runner.py +175 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/core_tests.egg-info/PKG-INFO +77 -93
- core_tests-2.2.0/core_tests.egg-info/requires.txt +6 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/pyproject.toml +6 -4
- core_tests-2.0.5/core_tests/tests/__init__.py +0 -0
- core_tests-2.0.5/core_tests/tests/runner.py +0 -226
- core_tests-2.0.5/core_tests.egg-info/requires.txt +0 -8
- {core_tests-2.0.5 → core_tests-2.2.0}/LICENSE +0 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/core_tests/py.typed +0 -0
- {core_tests-2.0.5/core_tests → core_tests-2.2.0/core_tests/tests}/__init__.py +0 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/core_tests.egg-info/SOURCES.txt +0 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/core_tests.egg-info/dependency_links.txt +0 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/core_tests.egg-info/top_level.txt +0 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/setup.cfg +0 -0
- {core_tests-2.0.5 → core_tests-2.2.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: core-tests
|
|
3
|
-
Version: 2.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
|
|
@@ -23,29 +23,39 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
24
|
Classifier: Programming Language :: Python :: 3.13
|
|
25
25
|
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
26
27
|
Requires-Python: >=3.9
|
|
27
28
|
Description-Content-Type: text/x-rst
|
|
28
29
|
License-File: LICENSE
|
|
29
30
|
Requires-Dist: click>=8.1.8
|
|
30
31
|
Requires-Dist: coverage>=7.7.1
|
|
31
32
|
Requires-Dist: environs>=14.1.1
|
|
32
|
-
Requires-Dist: pytest>=7.4.0
|
|
33
|
-
Requires-Dist: pytest-xdist>=3.5.0
|
|
34
33
|
Provides-Extra: dev
|
|
35
|
-
Requires-Dist: core-dev-tools>=
|
|
34
|
+
Requires-Dist: core-dev-tools>=2.1.0; extra == "dev"
|
|
36
35
|
Dynamic: license-file
|
|
37
36
|
|
|
38
37
|
core-tests
|
|
39
38
|
===============================================================================
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
A reusable library that provides CLI commands for running ``unittest``-based
|
|
41
|
+
tests and generating code coverage reports. It wraps Python's built-in
|
|
42
|
+
``unittest`` framework and ``coverage`` into a ``Click`` command group so
|
|
43
|
+
consuming projects can use ``python manager.py run-tests`` and
|
|
44
|
+
``python manager.py run-coverage`` without duplicating that logic across
|
|
45
|
+
every project in the ecosystem.
|
|
46
|
+
|
|
47
|
+
This library is intentionally scoped to ``unittest`` and ``coverage``.
|
|
48
|
+
If your project requires ``pytest``-specific features (fixtures, parametrize,
|
|
49
|
+
plugins, parallel execution), install ``pytest`` directly or via
|
|
50
|
+
``core-dev-tools`` and invoke it standalone — it is a better fit for that use
|
|
51
|
+
case than routing it through this abstraction layer.
|
|
46
52
|
|
|
47
53
|
===============================================================================
|
|
48
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
|
+
|
|
49
59
|
.. image:: https://img.shields.io/pypi/pyversions/core-tests.svg
|
|
50
60
|
:target: https://pypi.org/project/core-tests/
|
|
51
61
|
:alt: Python Versions
|
|
@@ -83,21 +93,34 @@ Install from PyPI using pip:
|
|
|
83
93
|
Features
|
|
84
94
|
===============================================================================
|
|
85
95
|
|
|
86
|
-
* **
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
* **Unified CLI abstraction**: Expose ``run-tests`` and ``run-coverage`` in any
|
|
97
|
+
project without duplicating boilerplate — just wire ``cli_tests`` into your
|
|
98
|
+
``CommandCollection``.
|
|
99
|
+
* **Flexible Test Discovery**: Supports multiple file patterns out of the box:
|
|
100
|
+
|
|
101
|
+
- ``test_*.py`` (standard pattern)
|
|
102
|
+
- ``*_test.py`` (alternative pattern)
|
|
103
|
+
- ``tests_*.py`` (custom pattern)
|
|
104
|
+
|
|
105
|
+
* **Custom Pattern Support**: Override discovery with ``--pattern`` for
|
|
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.
|
|
112
|
+
* **Test Organization**: Target specific test directories (unit, integration,
|
|
113
|
+
functional, etc.) via ``--test-type``.
|
|
114
|
+
* **Branch Coverage Reports**: Generate branch-level coverage reports and
|
|
115
|
+
optional HTML output.
|
|
116
|
+
* **DRY principle**: One implementation shared across all projects in the
|
|
117
|
+
ecosystem.
|
|
95
118
|
|
|
96
119
|
|
|
97
120
|
How to Use
|
|
98
121
|
===============================================================================
|
|
99
122
|
|
|
100
|
-
Create a ``manager.py`` file in your project root to integrate
|
|
123
|
+
Create a ``manager.py`` file in your project root to integrate
|
|
101
124
|
the test commands:
|
|
102
125
|
|
|
103
126
|
.. code-block:: python
|
|
@@ -112,7 +135,7 @@ the test commands:
|
|
|
112
135
|
|
|
113
136
|
This setup provides two commands:
|
|
114
137
|
|
|
115
|
-
* ``run-tests``: Execute test suites
|
|
138
|
+
* ``run-tests``: Execute unittest-based test suites
|
|
116
139
|
* ``run-coverage``: Generate code coverage reports
|
|
117
140
|
|
|
118
141
|
Example usage:
|
|
@@ -120,7 +143,7 @@ Example usage:
|
|
|
120
143
|
.. code-block:: bash
|
|
121
144
|
|
|
122
145
|
python manager.py run-tests --test-type unit
|
|
123
|
-
python manager.py run-coverage
|
|
146
|
+
python manager.py run-coverage
|
|
124
147
|
|
|
125
148
|
|
|
126
149
|
Available Commands
|
|
@@ -129,49 +152,56 @@ Available Commands
|
|
|
129
152
|
run-tests
|
|
130
153
|
-------------------------------------------------------------------------------
|
|
131
154
|
|
|
132
|
-
Execute test suites with flexible options:
|
|
155
|
+
Execute unittest-based test suites with flexible options:
|
|
133
156
|
|
|
134
157
|
**Options:**
|
|
135
158
|
|
|
136
|
-
* ``--
|
|
137
|
-
|
|
138
|
-
* ``--pattern``: File pattern to match test files (e.g., ``*.py``,
|
|
159
|
+
* ``--test-type``: Folder name under ``./tests`` directory (e.g., ``unit``,
|
|
160
|
+
``integration``, ``functional``). Default: ``unit``
|
|
161
|
+
* ``--pattern``: File pattern to match test files (e.g., ``*.py``,
|
|
162
|
+
``test_*.py``). Defaults to multi-pattern discovery.
|
|
139
163
|
|
|
140
164
|
**Examples:**
|
|
141
165
|
|
|
142
166
|
.. code-block:: bash
|
|
143
167
|
|
|
144
|
-
# Run unit tests
|
|
168
|
+
# Run unit tests (default)
|
|
145
169
|
python manager.py run-tests --test-type unit
|
|
146
170
|
|
|
147
|
-
# Run integration tests
|
|
148
|
-
python manager.py run-tests --
|
|
171
|
+
# Run integration tests
|
|
172
|
+
python manager.py run-tests --test-type integration
|
|
149
173
|
|
|
150
|
-
# Run tests with custom pattern
|
|
151
|
-
python manager.py run-tests --test-type functional --pattern "
|
|
174
|
+
# Run tests with a custom file pattern
|
|
175
|
+
python manager.py run-tests --test-type functional --pattern "*.py"
|
|
152
176
|
|
|
153
|
-
# Run
|
|
177
|
+
# Run tests in a custom folder
|
|
154
178
|
python manager.py run-tests --test-type "custom_folder"
|
|
155
179
|
|
|
156
180
|
|
|
157
181
|
run-coverage
|
|
158
182
|
-------------------------------------------------------------------------------
|
|
159
183
|
|
|
160
|
-
Generate code coverage reports:
|
|
184
|
+
Generate code coverage reports across all test directories:
|
|
161
185
|
|
|
162
186
|
**Options:**
|
|
163
187
|
|
|
164
|
-
* ``--
|
|
188
|
+
* ``--save-report``: Save HTML, XML and data coverage reports to disk.
|
|
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.
|
|
165
193
|
|
|
166
194
|
**Examples:**
|
|
167
195
|
|
|
168
196
|
.. code-block:: bash
|
|
169
197
|
|
|
170
|
-
# Generate coverage with unittest
|
|
171
198
|
python manager.py run-coverage
|
|
199
|
+
python manager.py run-coverage --save-report false
|
|
200
|
+
python manager.py run-coverage --fail-under 90
|
|
172
201
|
|
|
173
|
-
|
|
174
|
-
|
|
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.
|
|
175
205
|
|
|
176
206
|
|
|
177
207
|
Quick Start
|
|
@@ -213,78 +243,32 @@ Tests and Coverage
|
|
|
213
243
|
|
|
214
244
|
python manager.py run-tests --test-type unit
|
|
215
245
|
python manager.py run-tests --test-type integration
|
|
216
|
-
python manager.py run-tests --test-type "another folder that contains test cases under ./tests"
|
|
217
246
|
python manager.py run-tests --test-type functional --pattern "*.py"
|
|
247
|
+
python manager.py run-coverage
|
|
218
248
|
|
|
219
249
|
|
|
220
|
-
Using
|
|
250
|
+
Using pytest directly
|
|
221
251
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
222
252
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
conventions. Pytest-style tests (i.e., functions named test_* that are not inside a
|
|
226
|
-
`unittest.TestCase` class, or tests using pytest fixtures, parametrize, etc.) are not
|
|
227
|
-
recognized by unittest's discovery mechanism, `unittest` will simply ignore standalone
|
|
228
|
-
test functions and any pytest-specific features...
|
|
229
|
-
|
|
230
|
-
That's why you can use PyTest if required.
|
|
253
|
+
``unittest`` cannot discover standalone ``test_*`` functions or use pytest
|
|
254
|
+
fixtures. If your project relies on those features, invoke ``pytest`` directly:
|
|
231
255
|
|
|
232
256
|
.. code-block:: bash
|
|
233
257
|
|
|
234
|
-
|
|
258
|
+
pytest tests/unit/
|
|
259
|
+
pytest -n auto --cov=your_package --cov-report=html
|
|
235
260
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
Test coverage
|
|
239
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
261
|
+
Install ``pytest`` via ``pip`` or through ``core-dev-tools``:
|
|
240
262
|
|
|
241
263
|
.. code-block:: bash
|
|
242
264
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
265
|
+
pip install pytest pytest-xdist pytest-cov
|
|
266
|
+
# or
|
|
267
|
+
pip install ".[dev]" # if core-dev-tools includes pytest
|
|
246
268
|
|
|
247
269
|
..
|
|
248
270
|
|
|
249
271
|
|
|
250
|
-
Best Practices
|
|
251
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
252
|
-
|
|
253
|
-
When working with pytest, consider these optimization strategies:
|
|
254
|
-
|
|
255
|
-
1. **Use parallel execution for independent tests:**
|
|
256
|
-
|
|
257
|
-
.. code-block:: bash
|
|
258
|
-
|
|
259
|
-
pytest -n auto
|
|
260
|
-
|
|
261
|
-
..
|
|
262
|
-
|
|
263
|
-
2. **Run fast unit tests first during development:**
|
|
264
|
-
|
|
265
|
-
.. code-block:: bash
|
|
266
|
-
|
|
267
|
-
pytest tests/unit/ -n auto
|
|
268
|
-
|
|
269
|
-
..
|
|
270
|
-
|
|
271
|
-
3. **Run functional tests with limited parallelism:**
|
|
272
|
-
|
|
273
|
-
.. code-block:: bash
|
|
274
|
-
|
|
275
|
-
pytest tests/functional/ -n 2 # Avoid AWS rate limits
|
|
276
|
-
|
|
277
|
-
..
|
|
278
|
-
|
|
279
|
-
4. **Use markers to run specific test subsets:**
|
|
280
|
-
|
|
281
|
-
.. code-block:: bash
|
|
282
|
-
|
|
283
|
-
pytest -m "unit and not slow" -n auto
|
|
284
|
-
|
|
285
|
-
..
|
|
286
|
-
|
|
287
|
-
|
|
288
272
|
Contributing
|
|
289
273
|
===============================================================================
|
|
290
274
|
|
|
@@ -293,7 +277,7 @@ Contributions are welcome! Please:
|
|
|
293
277
|
1. Fork the repository
|
|
294
278
|
2. Create a feature branch
|
|
295
279
|
3. Write tests for new functionality
|
|
296
|
-
4. Ensure all tests pass: ``
|
|
280
|
+
4. Ensure all tests pass: ``python manager.py run-tests --test-type unit``
|
|
297
281
|
5. Run linting: ``pylint core_tests``
|
|
298
282
|
6. Run security checks: ``bandit -r core_tests``
|
|
299
283
|
7. Submit a pull request
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
core-tests
|
|
2
2
|
===============================================================================
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
A reusable library that provides CLI commands for running ``unittest``-based
|
|
5
|
+
tests and generating code coverage reports. It wraps Python's built-in
|
|
6
|
+
``unittest`` framework and ``coverage`` into a ``Click`` command group so
|
|
7
|
+
consuming projects can use ``python manager.py run-tests`` and
|
|
8
|
+
``python manager.py run-coverage`` without duplicating that logic across
|
|
9
|
+
every project in the ecosystem.
|
|
10
|
+
|
|
11
|
+
This library is intentionally scoped to ``unittest`` and ``coverage``.
|
|
12
|
+
If your project requires ``pytest``-specific features (fixtures, parametrize,
|
|
13
|
+
plugins, parallel execution), install ``pytest`` directly or via
|
|
14
|
+
``core-dev-tools`` and invoke it standalone — it is a better fit for that use
|
|
15
|
+
case than routing it through this abstraction layer.
|
|
9
16
|
|
|
10
17
|
===============================================================================
|
|
11
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
|
+
|
|
12
23
|
.. image:: https://img.shields.io/pypi/pyversions/core-tests.svg
|
|
13
24
|
:target: https://pypi.org/project/core-tests/
|
|
14
25
|
:alt: Python Versions
|
|
@@ -46,21 +57,34 @@ Install from PyPI using pip:
|
|
|
46
57
|
Features
|
|
47
58
|
===============================================================================
|
|
48
59
|
|
|
49
|
-
* **
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
* **Unified CLI abstraction**: Expose ``run-tests`` and ``run-coverage`` in any
|
|
61
|
+
project without duplicating boilerplate — just wire ``cli_tests`` into your
|
|
62
|
+
``CommandCollection``.
|
|
63
|
+
* **Flexible Test Discovery**: Supports multiple file patterns out of the box:
|
|
64
|
+
|
|
65
|
+
- ``test_*.py`` (standard pattern)
|
|
66
|
+
- ``*_test.py`` (alternative pattern)
|
|
67
|
+
- ``tests_*.py`` (custom pattern)
|
|
68
|
+
|
|
69
|
+
* **Custom Pattern Support**: Override discovery with ``--pattern`` for
|
|
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.
|
|
76
|
+
* **Test Organization**: Target specific test directories (unit, integration,
|
|
77
|
+
functional, etc.) via ``--test-type``.
|
|
78
|
+
* **Branch Coverage Reports**: Generate branch-level coverage reports and
|
|
79
|
+
optional HTML output.
|
|
80
|
+
* **DRY principle**: One implementation shared across all projects in the
|
|
81
|
+
ecosystem.
|
|
58
82
|
|
|
59
83
|
|
|
60
84
|
How to Use
|
|
61
85
|
===============================================================================
|
|
62
86
|
|
|
63
|
-
Create a ``manager.py`` file in your project root to integrate
|
|
87
|
+
Create a ``manager.py`` file in your project root to integrate
|
|
64
88
|
the test commands:
|
|
65
89
|
|
|
66
90
|
.. code-block:: python
|
|
@@ -75,7 +99,7 @@ the test commands:
|
|
|
75
99
|
|
|
76
100
|
This setup provides two commands:
|
|
77
101
|
|
|
78
|
-
* ``run-tests``: Execute test suites
|
|
102
|
+
* ``run-tests``: Execute unittest-based test suites
|
|
79
103
|
* ``run-coverage``: Generate code coverage reports
|
|
80
104
|
|
|
81
105
|
Example usage:
|
|
@@ -83,7 +107,7 @@ Example usage:
|
|
|
83
107
|
.. code-block:: bash
|
|
84
108
|
|
|
85
109
|
python manager.py run-tests --test-type unit
|
|
86
|
-
python manager.py run-coverage
|
|
110
|
+
python manager.py run-coverage
|
|
87
111
|
|
|
88
112
|
|
|
89
113
|
Available Commands
|
|
@@ -92,49 +116,56 @@ Available Commands
|
|
|
92
116
|
run-tests
|
|
93
117
|
-------------------------------------------------------------------------------
|
|
94
118
|
|
|
95
|
-
Execute test suites with flexible options:
|
|
119
|
+
Execute unittest-based test suites with flexible options:
|
|
96
120
|
|
|
97
121
|
**Options:**
|
|
98
122
|
|
|
99
|
-
* ``--
|
|
100
|
-
|
|
101
|
-
* ``--pattern``: File pattern to match test files (e.g., ``*.py``,
|
|
123
|
+
* ``--test-type``: Folder name under ``./tests`` directory (e.g., ``unit``,
|
|
124
|
+
``integration``, ``functional``). Default: ``unit``
|
|
125
|
+
* ``--pattern``: File pattern to match test files (e.g., ``*.py``,
|
|
126
|
+
``test_*.py``). Defaults to multi-pattern discovery.
|
|
102
127
|
|
|
103
128
|
**Examples:**
|
|
104
129
|
|
|
105
130
|
.. code-block:: bash
|
|
106
131
|
|
|
107
|
-
# Run unit tests
|
|
132
|
+
# Run unit tests (default)
|
|
108
133
|
python manager.py run-tests --test-type unit
|
|
109
134
|
|
|
110
|
-
# Run integration tests
|
|
111
|
-
python manager.py run-tests --
|
|
135
|
+
# Run integration tests
|
|
136
|
+
python manager.py run-tests --test-type integration
|
|
112
137
|
|
|
113
|
-
# Run tests with custom pattern
|
|
114
|
-
python manager.py run-tests --test-type functional --pattern "
|
|
138
|
+
# Run tests with a custom file pattern
|
|
139
|
+
python manager.py run-tests --test-type functional --pattern "*.py"
|
|
115
140
|
|
|
116
|
-
# Run
|
|
141
|
+
# Run tests in a custom folder
|
|
117
142
|
python manager.py run-tests --test-type "custom_folder"
|
|
118
143
|
|
|
119
144
|
|
|
120
145
|
run-coverage
|
|
121
146
|
-------------------------------------------------------------------------------
|
|
122
147
|
|
|
123
|
-
Generate code coverage reports:
|
|
148
|
+
Generate code coverage reports across all test directories:
|
|
124
149
|
|
|
125
150
|
**Options:**
|
|
126
151
|
|
|
127
|
-
* ``--
|
|
152
|
+
* ``--save-report``: Save HTML, XML and data coverage reports to disk.
|
|
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.
|
|
128
157
|
|
|
129
158
|
**Examples:**
|
|
130
159
|
|
|
131
160
|
.. code-block:: bash
|
|
132
161
|
|
|
133
|
-
# Generate coverage with unittest
|
|
134
162
|
python manager.py run-coverage
|
|
163
|
+
python manager.py run-coverage --save-report false
|
|
164
|
+
python manager.py run-coverage --fail-under 90
|
|
135
165
|
|
|
136
|
-
|
|
137
|
-
|
|
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.
|
|
138
169
|
|
|
139
170
|
|
|
140
171
|
Quick Start
|
|
@@ -176,78 +207,32 @@ Tests and Coverage
|
|
|
176
207
|
|
|
177
208
|
python manager.py run-tests --test-type unit
|
|
178
209
|
python manager.py run-tests --test-type integration
|
|
179
|
-
python manager.py run-tests --test-type "another folder that contains test cases under ./tests"
|
|
180
210
|
python manager.py run-tests --test-type functional --pattern "*.py"
|
|
211
|
+
python manager.py run-coverage
|
|
181
212
|
|
|
182
213
|
|
|
183
|
-
Using
|
|
214
|
+
Using pytest directly
|
|
184
215
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
185
216
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
conventions. Pytest-style tests (i.e., functions named test_* that are not inside a
|
|
189
|
-
`unittest.TestCase` class, or tests using pytest fixtures, parametrize, etc.) are not
|
|
190
|
-
recognized by unittest's discovery mechanism, `unittest` will simply ignore standalone
|
|
191
|
-
test functions and any pytest-specific features...
|
|
192
|
-
|
|
193
|
-
That's why you can use PyTest if required.
|
|
217
|
+
``unittest`` cannot discover standalone ``test_*`` functions or use pytest
|
|
218
|
+
fixtures. If your project relies on those features, invoke ``pytest`` directly:
|
|
194
219
|
|
|
195
220
|
.. code-block:: bash
|
|
196
221
|
|
|
197
|
-
|
|
222
|
+
pytest tests/unit/
|
|
223
|
+
pytest -n auto --cov=your_package --cov-report=html
|
|
198
224
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
Test coverage
|
|
202
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
225
|
+
Install ``pytest`` via ``pip`` or through ``core-dev-tools``:
|
|
203
226
|
|
|
204
227
|
.. code-block:: bash
|
|
205
228
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
229
|
+
pip install pytest pytest-xdist pytest-cov
|
|
230
|
+
# or
|
|
231
|
+
pip install ".[dev]" # if core-dev-tools includes pytest
|
|
209
232
|
|
|
210
233
|
..
|
|
211
234
|
|
|
212
235
|
|
|
213
|
-
Best Practices
|
|
214
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
215
|
-
|
|
216
|
-
When working with pytest, consider these optimization strategies:
|
|
217
|
-
|
|
218
|
-
1. **Use parallel execution for independent tests:**
|
|
219
|
-
|
|
220
|
-
.. code-block:: bash
|
|
221
|
-
|
|
222
|
-
pytest -n auto
|
|
223
|
-
|
|
224
|
-
..
|
|
225
|
-
|
|
226
|
-
2. **Run fast unit tests first during development:**
|
|
227
|
-
|
|
228
|
-
.. code-block:: bash
|
|
229
|
-
|
|
230
|
-
pytest tests/unit/ -n auto
|
|
231
|
-
|
|
232
|
-
..
|
|
233
|
-
|
|
234
|
-
3. **Run functional tests with limited parallelism:**
|
|
235
|
-
|
|
236
|
-
.. code-block:: bash
|
|
237
|
-
|
|
238
|
-
pytest tests/functional/ -n 2 # Avoid AWS rate limits
|
|
239
|
-
|
|
240
|
-
..
|
|
241
|
-
|
|
242
|
-
4. **Use markers to run specific test subsets:**
|
|
243
|
-
|
|
244
|
-
.. code-block:: bash
|
|
245
|
-
|
|
246
|
-
pytest -m "unit and not slow" -n auto
|
|
247
|
-
|
|
248
|
-
..
|
|
249
|
-
|
|
250
|
-
|
|
251
236
|
Contributing
|
|
252
237
|
===============================================================================
|
|
253
238
|
|
|
@@ -256,7 +241,7 @@ Contributions are welcome! Please:
|
|
|
256
241
|
1. Fork the repository
|
|
257
242
|
2. Create a feature branch
|
|
258
243
|
3. Write tests for new functionality
|
|
259
|
-
4. Ensure all tests pass: ``
|
|
244
|
+
4. Ensure all tests pass: ``python manager.py run-tests --test-type unit``
|
|
260
245
|
5. Run linting: ``pylint core_tests``
|
|
261
246
|
6. Run security checks: ``bandit -r core_tests``
|
|
262
247
|
7. Submit a pull request
|
|
@@ -287,4 +272,4 @@ For questions or support, please open an issue on GitLab or contact the maintain
|
|
|
287
272
|
Authors
|
|
288
273
|
===============================================================================
|
|
289
274
|
|
|
290
|
-
* **Alejandro Cora González** - *Initial work* - alek.cora.glez@gmail.com
|
|
275
|
+
* **Alejandro Cora González** - *Initial work* - alek.cora.glez@gmail.com
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Provides common elements for testing purposes.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
|
|
7
|
+
from core_tests.tests.base import BaseTestCase
|
|
8
|
+
from core_tests.tests.runner import cli_tests
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("core-tests")
|
|
12
|
+
|
|
13
|
+
except PackageNotFoundError:
|
|
14
|
+
__version__ = "unknown"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"BaseTestCase",
|
|
19
|
+
"__version__",
|
|
20
|
+
"cli_tests",
|
|
21
|
+
]
|