Skip to content

Commit

Permalink
[FIX] sale_order_product_recommendation: freezegun hack
Browse files Browse the repository at this point in the history
As seen in spulec/freezegun#485, when decorating a class with `@freezegun.freeze_time()`, class cleanups are not properly executed.

For Odoo, this means that the cursor is not properly closed. Thus, if you happen to run a test for another module after this one that needs a Postgres-level lock that conflicts with this module's, it will fail.

This change does the same, but without decorating the class. Then, the cleanups work as expected.

@moduon MT-1075
  • Loading branch information
yajo committed Oct 26, 2023
1 parent a38d80d commit a3cd57d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .test_recommendation_common import RecommendationCase


@freeze_time("2021-10-02 15:30:00")
class RecommendationCaseTests(RecommendationCase):
def test_recommendations(self):
"""Recommendations are OK."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
from odoo.tests.common import TransactionCase


@freeze_time("2021-10-02 15:30:00")
class RecommendationCase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# HACK https://github.com/spulec/freezegun/issues/485
freezer = freeze_time("2021-10-02 15:30:00")
freezer.__enter__()
cls.addClassCleanup(freezer.__exit__)
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
Expand Down

0 comments on commit a3cd57d

Please sign in to comment.