-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57d7ef2
commit bb321e1
Showing
11 changed files
with
754 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../tests_summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
============ | ||
Test Summary | ||
============ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:126364c9ac7a093bc9b07176ff3b3cf0026146b57743ec5486d79788f96cd1e7 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github | ||
:target: https://github.com/OCA/server-tools/tree/14.0/tests_summary | ||
:alt: OCA/server-tools | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-tests_summary | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Add this module to your ``server_wide_modules`` list in your odoo.conf | ||
file to enable the tests summary feature. | ||
|
||
At the end of the tests, a summary will be displayed in the logs for | ||
quick review of the test failures grouped by module. | ||
|
||
The summary will look like this: | ||
|
||
|Tests Summary Tests Summary| | ||
|
||
.. |Tests Summary Tests Summary| image:: https://raw.githubusercontent.com/OCA/server-tools/14.0/tests_summary/static/description/tests_summary.png | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20tests_summary%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* Akretion | ||
|
||
Contributors | ||
------------ | ||
|
||
- Florian Mounier [email protected] | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-paradoxxxzero| image:: https://github.com/paradoxxxzero.png?size=40px | ||
:target: https://github.com/paradoxxxzero | ||
:alt: paradoxxxzero | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-paradoxxxzero| | ||
|
||
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/14.0/tests_summary>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from unittest.mock import patch | ||
from collections import defaultdict | ||
import logging | ||
import re | ||
import os | ||
|
||
from odoo.tools import config | ||
from odoo.service.server import preload_registries | ||
from odoo.modules.registry import Registry | ||
|
||
|
||
class Colorize: | ||
colors = ("black", "red", "green", "yellow", "blue", "magenta", "cyan", "white") | ||
|
||
def __init__(self, logger): | ||
self.active = os.name == "posix" and all( | ||
isinstance(handler, logging.StreamHandler) | ||
and hasattr(handler.stream, "fileno") | ||
and os.isatty(handler.stream.fileno()) | ||
for handler in logger.handlers | ||
) | ||
|
||
def bold(self, text): | ||
if not self.active: | ||
return text | ||
return f"\033[1m{text}\033[0m" | ||
|
||
def color(self, text, color, bold=False): | ||
if not self.active: | ||
return text | ||
return ( | ||
f"\033[{30 + self.colors.index(color)}{';1' if bold else ''}m{text}\033[0m" | ||
) | ||
|
||
def __getattr__(self, attr): | ||
if attr in self.colors: | ||
return lambda text, bold=False: self.color(text, attr, bold) | ||
return super().__getattr__(attr) | ||
|
||
|
||
def maybe_pluralize(n, singular, plural=None): | ||
return f"{n} {singular if n == 1 else (plural or singular + 's')}" | ||
|
||
|
||
module_re = re.compile(r"odoo\.addons\.(\w+)") | ||
|
||
|
||
def get_module(test): | ||
if hasattr(test, "test_module"): | ||
return test.test_module | ||
for key in ("description", "test_description", "test_id"): | ||
if hasattr(test, key): | ||
match = module_re.search(getattr(test, key)) | ||
if match: | ||
return match.group(1) | ||
return "unknown (%s)" % repr(test) | ||
|
||
|
||
def get_test_name(test): | ||
if hasattr(test, "_testMethodName"): | ||
name = "" | ||
if hasattr(test, "test_class"): | ||
name += test.test_class + "." | ||
name += test._testMethodName | ||
return name | ||
for key in ("description", "test_description", "test_id"): | ||
if getattr(test, key, False): | ||
return getattr(test, key) | ||
return "unknown (%s)" % repr(test) | ||
|
||
|
||
def preload_registries_and_display_test_results(dbnames): | ||
_logger = logging.getLogger(__name__) | ||
rc = preload_registries(dbnames) | ||
c = Colorize(_logger) | ||
types = { | ||
"errors": "error", | ||
"failures": "failure", | ||
"skipped": "skip", | ||
"expectedFailures": "expected failure", | ||
"unexpectedSuccesses": "unexpected success", | ||
} | ||
colors = { | ||
"errors": "red", | ||
"failures": "red", | ||
"skipped": "yellow", | ||
"expectedFailures": "green", | ||
"unexpectedSuccesses": "cyan", | ||
} | ||
for db in dbnames: | ||
report = Registry.registries[db]._assertion_report | ||
|
||
modules_infos = defaultdict(list) | ||
for type_ in types: | ||
for test_info in getattr(report, type_): | ||
test, info = ( | ||
test_info | ||
if isinstance(test_info, tuple) and len(test_info) == 2 | ||
else (test_info, "Success") | ||
) | ||
modules_infos[get_module(test)].append( | ||
{"type": type_, "info": info, "test": test} | ||
) | ||
|
||
message = "\n\n" + c.bold(f"Database {db}: ") + f"{report.testsRun} tests run" | ||
for type_, type_name in types.items(): | ||
if getattr(report, type_): | ||
message += ", " + c.color( | ||
maybe_pluralize(len(getattr(report, type_)), type_name), | ||
colors[type_], | ||
True, | ||
) | ||
|
||
if len(modules_infos): | ||
message += f" in {len(modules_infos)} modules." | ||
|
||
message += "\n\n" | ||
|
||
for module, infos in modules_infos.items(): | ||
message += c.black("+" + "-" * (len(module) + 2) + "+", True) + "\n" | ||
message += c.black("| ", True) + c.bold(module) + c.black(" |", True) + "\n" | ||
message += c.black("+" + "-" * (len(module) + 2) + "+", True) + "\n" | ||
for type_, type_name in types.items(): | ||
type_infos = [info for info in infos if info["type"] == type_] | ||
if type_infos: | ||
message += ( | ||
c.color( | ||
maybe_pluralize(len(type_infos), type_name) + ":", | ||
colors[type_], | ||
True, | ||
) | ||
+ "\n" | ||
) | ||
for info in type_infos: | ||
message += ( | ||
c.black( | ||
" - " | ||
+ ( | ||
(info["test"].__module__.split(".")[-1] + ":") | ||
if getattr(info["test"], "__module__", False) | ||
else "" | ||
), | ||
True, | ||
) | ||
+ c.bold(get_test_name(info["test"]) + ":") | ||
+ "\n" | ||
) | ||
message += info["info"].rstrip("\n") + "\n\n" | ||
|
||
getattr(_logger, "error" if report.errors or report.failures else "info")( | ||
message | ||
) | ||
|
||
return rc | ||
|
||
|
||
if config["test_enable"]: | ||
patch( | ||
"odoo.service.server.preload_registries", | ||
preload_registries_and_display_test_results, | ||
).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Test Summary", | ||
"version": "14.0.1.0.0", | ||
"author": "Akretion,Odoo Community Association (OCA)", | ||
"summary": "Odoo patch to display a summary of failed tests at the end " | ||
"of odoo startup", | ||
"website": "https://github.com/OCA/server-tools", | ||
"maintainers": ["paradoxxxzero"], | ||
"license": "AGPL-3", | ||
"category": "Generic Modules", | ||
"depends": [], | ||
"data": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Florian Mounier <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Add this module to your `server_wide_modules` list in your odoo.conf file to enable the | ||
tests summary feature. | ||
|
||
At the end of the tests, a summary will be displayed in the logs for quick review of the | ||
test failures grouped by module. | ||
|
||
The summary will look like this: | ||
|
||
![Tests Summary Tests Summary](../static/description/tests_summary.png) |
Oops, something went wrong.