Skip to content

Commit

Permalink
[FIX] extendable_fastapi: Registry corruption in tests
Browse files Browse the repository at this point in the history
Register the cleanup of the extendable registry just after its initialisation by calling the  method from unittest. If setUpClass() fails, meaning that tearDownClass() is not called, then any cleanup functions added with a call to  will still be called.

refs #392
  • Loading branch information
lmignon committed Nov 7, 2023
1 parent 2326fed commit db9a92c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
6 changes: 1 addition & 5 deletions base_rest_demo/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def setUpClass(cls):
model_name="rest.service.registration", collection=collection
)
cls.init_extendable_registry()

@classmethod
def tearDownClass(cls):
cls.reset_extendable_registry()
super().tearDownClass()
cls.addClassCleanup(cls.reset_extendable_registry)

# pylint: disable=W8106
def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion extendable_fastapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Extendable Fastapi
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:959cc91eecf414d64d236339357d4322403e81584fb614d58d650f238d69fb93
!! source digest: sha256:56a7bf28deffc71b10441926e9f063ba543c88d1c849dee1ae89b9500cdcda1f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
1 change: 1 addition & 0 deletions extendable_fastapi/readme/newsfragments/392.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix registry corruption when running tests difined in a class inheriting of the *FastAPITransactionCase* class if an error occurs in the *setUpClass* after the call to super().
2 changes: 1 addition & 1 deletion extendable_fastapi/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Extendable Fastapi</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:959cc91eecf414d64d236339357d4322403e81584fb614d58d650f238d69fb93
!! source digest: sha256:56a7bf28deffc71b10441926e9f063ba543c88d1c849dee1ae89b9500cdcda1f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/extendable_fastapi"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-extendable_fastapi"><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/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon is a technical addon used to allows the use of
Expand Down
6 changes: 1 addition & 5 deletions extendable_fastapi/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ class FastAPITransactionCase(BaseFastAPITransactionCase, ExtendableMixin):
def setUpClass(cls) -> None:
super().setUpClass()
cls.init_extendable_registry()

@classmethod
def tearDownClass(cls) -> None:
cls.reset_extendable_registry()
super().tearDownClass()
cls.addClassCleanup(cls.reset_extendable_registry)

0 comments on commit db9a92c

Please sign in to comment.