pytest-max-warnings 0.1.0__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,44 @@
1
+ from __future__ import annotations
2
+
3
+ import pytest
4
+
5
+
6
+ _STASH_KEY = pytest.StashKey["bool"]()
7
+
8
+
9
+ def pytest_addoption(parser: pytest.Parser) -> None:
10
+ group = parser.getgroup("pytest-max-warnings")
11
+ group.addoption(
12
+ "--max-warnings",
13
+ action="store",
14
+ type=int,
15
+ default=None,
16
+ help="Max number of warnings before failing",
17
+ )
18
+
19
+
20
+ @pytest.hookimpl(trylast=True)
21
+ def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
22
+ max_warnings = session.config.option.max_warnings
23
+ terminal_reporter = session.config.pluginmanager.get_plugin("terminalreporter")
24
+ assert terminal_reporter is not None
25
+
26
+ warnings_summary = terminal_reporter.stats.get("warnings", [])
27
+
28
+ if max_warnings is not None and len(warnings_summary) > max_warnings:
29
+ session.exitstatus = 100
30
+ session.config.stash[_STASH_KEY] = True
31
+
32
+
33
+ def pytest_terminal_summary(terminalreporter, exitstatus, config):
34
+ max_warnings = config.option.max_warnings
35
+ warnings_summary = terminalreporter.stats.get("warnings", [])
36
+
37
+ exceeded_max_warnings = config.stash.get(_STASH_KEY, False)
38
+ if not exceeded_max_warnings:
39
+ return
40
+
41
+ terminalreporter.write_sep("=", "pytest-max-warnings")
42
+ terminalreporter.write_line(
43
+ f"ERROR: Exceeded the maximum allowed warnings: {len(warnings_summary)} > {max_warnings}"
44
+ )
File without changes
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.3
2
+ Name: pytest-max-warnings
3
+ Version: 0.1.0
4
+ Summary: A Pytest plugin to exit non-zero exit code when the configured maximum warnings has been exceeded.
5
+ Project-URL: Repository, https://github.com/miketheman/pytest-max-warnings
6
+ Author-email: Mike Fiedler <miketheman@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Framework :: Pytest
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: Implementation :: CPython
22
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
23
+ Classifier: Topic :: Software Development :: Testing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: pytest>=8.3.3
27
+ Description-Content-Type: text/markdown
28
+
29
+ # pytest-max-warnings
30
+
31
+ A Pytest plugin to exit non-zero exit code
32
+ when the configured maximum warnings has been exceeded.
33
+
34
+ ## Installation
35
+
36
+ You can install "pytest-max-warnings" via [pip](https://pypi.org/project/pytest-max-warnings/):
37
+
38
+ ```bash
39
+ pip install pytest-max-warnings
40
+ ```
41
+
42
+ or any other package manager you prefer.
43
+
44
+ ## Usage
45
+
46
+ You can set the maximum number of warnings allowed by using the `--max-warnings` option:
47
+
48
+ ```bash
49
+ pytest --max-warnings 10
50
+ ```
51
+
52
+ If the number of warnings exceeds the maximum, the test run will exit with a non-zero exit code.
53
+
54
+ ## License
55
+
56
+ Distributed under the terms of the MIT license, "pytest-max-warnings" is free and open source software.
57
+ See [LICENSE](./LICENSE) for more details.
58
+
59
+ ## Authors
60
+
61
+ - [@miketheman](https://github.com/miketheman)
@@ -0,0 +1,8 @@
1
+ pytest_max_warnings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ pytest_max_warnings/plugin.py,sha256=-LCb3dFIq2LhWKwFaNmTMkClNAbEVZQcnPzprDj8lIU,1372
3
+ pytest_max_warnings/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ pytest_max_warnings-0.1.0.dist-info/METADATA,sha256=EP_cpD8DoCHYy3lp2JhqxwvFRElN0_cfmXcL0RqqrSQ,2006
5
+ pytest_max_warnings-0.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
6
+ pytest_max_warnings-0.1.0.dist-info/entry_points.txt,sha256=-ZlTO0RLZcgX5iK8FGes4DyXald181viYGQv9CiHCO4,53
7
+ pytest_max_warnings-0.1.0.dist-info/licenses/LICENSE,sha256=IaClHZaNw46higl3oPW9eTaoLvD5ftrcWEue3hASOW0,1068
8
+ pytest_max_warnings-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.25.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ max-warnings = pytest_max_warnings.plugin
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mike Fiedler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.