Skip to content

Commit acab0d8

Browse files
committed
[BACKPORT] odoo_test_xmlrunner to 16.0
Also implement a better patch and merge test results.
1 parent c69b5d5 commit acab0d8

File tree

13 files changed

+86
-52
lines changed

13 files changed

+86
-52
lines changed

odoo_test_xmlrunner/README.rst

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Unittest xUnit reports
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:782b2ed22876a72d28e0e67c5ff949d6d104c2da4bd0cf36ca7dbf3597900604
10+
!! source digest: sha256:c168ead1259f832fbcdbe238c9bd5a9eb692d3e0c712130ab2103e4a2dcba36b
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Unittest xUnit reports
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
20-
:target: https://github.com/OCA/server-tools/tree/17.0/odoo_test_xmlrunner
20+
:target: https://github.com/OCA/server-tools/tree/16.0/odoo_test_xmlrunner
2121
:alt: OCA/server-tools
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-odoo_test_xmlrunner
23+
:target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-odoo_test_xmlrunner
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=16.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -164,7 +164,7 @@ Bug Tracker
164164
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
165165
In case of trouble, please check there if your issue has already been reported.
166166
If you spotted it first, help us to smash it by providing a detailed and welcomed
167-
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20odoo_test_xmlrunner%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
167+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20odoo_test_xmlrunner%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
168168

169169
Do not contact contributors directly about support or help with technical issues.
170170

@@ -179,9 +179,13 @@ Authors
179179
Other credits
180180
-------------
181181

182-
- `Smile <https://smile.eu/fr>`__:
182+
- `Smile <https://smile.eu/fr>`__:
183183

184-
- Martin Deconinck [email protected]
184+
- Martin Deconinck [email protected]
185+
186+
- `Akretion <https://akretion.com>`__:
187+
188+
- Florian Mounier [email protected]
185189

186190
Maintainers
187191
-----------
@@ -196,6 +200,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
196200
mission is to support the collaborative development of Odoo features and
197201
promote its widespread use.
198202

199-
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/17.0/odoo_test_xmlrunner>`_ project on GitHub.
203+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/odoo_test_xmlrunner>`_ project on GitHub.
200204

201205
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

odoo_test_xmlrunner/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import odoo_tests # F401 imported but unused
1+
from . import odoo_tests # F401 imported but unused

odoo_test_xmlrunner/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Unittest xUnit reports",
3-
"version": "17.0.1.0.0",
3+
"version": "16.0.1.0.0",
44
"depends": ["base"],
55
"author": "Smile, Odoo Community Association (OCA)",
66
"license": "AGPL-3",
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import loader # F401 imported but unused
1+
from . import loader # F401 imported but unused
+41-27
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
import os
2-
import threading
2+
from unittest.mock import patch
33

4-
import xmlrunner
4+
from xmlrunner import XMLTestRunner
5+
from xmlrunner.result import _XMLTestResult
56

6-
from odoo.tests import loader as odoo_loader
77
from odoo.tests.result import OdooTestResult
8+
from odoo.tests.suite import OdooSuite
89
from odoo.tools import config
910

10-
11-
def new_run_suite(suite, module_name=None):
12-
# Override : Get and create a config dir
13-
test_result_directory = config.get("test_result_directory", "test_results")
14-
# create test result directory if not exists
15-
if not os.path.exists(test_result_directory):
16-
os.makedirs(test_result_directory)
17-
18-
# avoid dependency hell
19-
from odoo.modules import module
20-
21-
module.current_test = module_name
22-
threading.current_thread().testing = True
23-
results = OdooTestResult()
24-
25-
# Override : XMLTestRunner to run the tests and generate XML reports
26-
xmlrunner.XMLTestRunner(output=test_result_directory, verbosity=2).run(suite)
27-
28-
threading.current_thread().testing = False
29-
module.current_test = None
30-
return results
31-
32-
33-
odoo_loader.run_suite = new_run_suite
11+
if config["test_enable"]:
12+
unpatched_run = OdooSuite.run
13+
14+
def run(self, result):
15+
# Override : Get and create a config dir
16+
test_result_directory = config.get("test_result_directory", "test_results")
17+
# create test result directory if not exists
18+
if not os.path.exists(test_result_directory):
19+
os.makedirs(test_result_directory)
20+
21+
# Suite run method will be called by the XMLTestRunner,
22+
# so we need to run the original run method
23+
with patch.object(self, "run", lambda result: unpatched_run(self, result)):
24+
# Override : XMLTestRunner to run the tests and generate XML reports
25+
results = XMLTestRunner(
26+
output=test_result_directory,
27+
verbosity=2,
28+
).run(self)
29+
30+
result.update(results)
31+
return result
32+
33+
patch("odoo.tests.suite.OdooSuite.run", run).start()
34+
35+
unpatched_update = OdooTestResult.update
36+
37+
def update(self, other):
38+
# Adapt _XMLTestResult to OdooTestResult
39+
if isinstance(other, _XMLTestResult):
40+
self.failures_count += len(other.failures)
41+
self.errors_count += len(other.errors)
42+
self.skipped += len(other.skipped)
43+
self.testsRun += other.testsRun
44+
else:
45+
unpatched_update(self, other)
46+
47+
patch("odoo.tests.result.OdooTestResult.update", update).start()
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Add to your odoo Configuration file:
2-
- **test_result_directory** (default: *test_results*) : The path (created if not exists) where the reports will be written to.
2+
- **test_result_directory** (default: *test_results*) : The path (created if not exists) where the reports will be written to.

odoo_test_xmlrunner/readme/CREDITS.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
* [Smile](https://smile.eu/fr):
2-
* Martin Deconinck <[email protected]>
1+
- [Smile](https://smile.eu/fr):
2+
- Martin Deconinck <[email protected]>
3+
- [Akretion](https://akretion.com):
4+
- Florian Mounier <[email protected]>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This module generate unittest reports using unittest-xml-reporting tool.
1+
This module generate unittest reports using unittest-xml-reporting tool.

odoo_test_xmlrunner/readme/INSTALL.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Install python library https://pypi.org/project/unittest-xml-reporting/
22

3-
The module is automatically installed on the Odoo instance.
3+
The module is automatically installed on the Odoo instance.

odoo_test_xmlrunner/readme/USAGE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ jobs:
105105
with:
106106
report_paths: 'test_results/*.xml'
107107
108-
```
108+
```

odoo_test_xmlrunner/static/description/index.html

+15-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -366,9 +367,9 @@ <h1 class="title">Unittest xUnit reports</h1>
366367
!! This file is generated by oca-gen-addon-readme !!
367368
!! changes will be overwritten. !!
368369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369-
!! source digest: sha256:782b2ed22876a72d28e0e67c5ff949d6d104c2da4bd0cf36ca7dbf3597900604
370+
!! source digest: sha256:c168ead1259f832fbcdbe238c9bd5a9eb692d3e0c712130ab2103e4a2dcba36b
370371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/17.0/odoo_test_xmlrunner"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-odoo_test_xmlrunner"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/odoo_test_xmlrunner"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-odoo_test_xmlrunner"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372373
<p>This module generate unittest reports using unittest-xml-reporting tool.</p>
373374
<p><strong>Table of contents</strong></p>
374375
<div class="contents local topic" id="contents">
@@ -511,7 +512,7 @@ <h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
511512
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
512513
In case of trouble, please check there if your issue has already been reported.
513514
If you spotted it first, help us to smash it by providing a detailed and welcomed
514-
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20odoo_test_xmlrunner%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
515+
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20odoo_test_xmlrunner%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
515516
<p>Do not contact contributors directly about support or help with technical issues.</p>
516517
</div>
517518
<div class="section" id="credits">
@@ -529,16 +530,22 @@ <h2><a class="toc-backref" href="#toc-entry-9">Other credits</a></h2>
529530
<li>Martin Deconinck <a class="reference external" href="mailto:martin.deconinck&#64;smile.fr">martin.deconinck&#64;smile.fr</a></li>
530531
</ul>
531532
</li>
533+
<li><a class="reference external" href="https://akretion.com">Akretion</a>:<ul>
534+
<li>Florian Mounier <a class="reference external" href="mailto:florian.mounier&#64;akretion.com">florian.mounier&#64;akretion.com</a></li>
535+
</ul>
536+
</li>
532537
</ul>
533538
</div>
534539
<div class="section" id="maintainers">
535540
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
536541
<p>This module is maintained by the OCA.</p>
537-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
542+
<a class="reference external image-reference" href="https://odoo-community.org">
543+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
544+
</a>
538545
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
539546
mission is to support the collaborative development of Odoo features and
540547
promote its widespread use.</p>
541-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/17.0/odoo_test_xmlrunner">OCA/server-tools</a> project on GitHub.</p>
548+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/16.0/odoo_test_xmlrunner">OCA/server-tools</a> project on GitHub.</p>
542549
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
543550
</div>
544551
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../odoo_test_xmlrunner

setup/odoo_test_xmlrunner/setup.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)