[18.0] base_exception: swallow_base_exception_error never runs the decorated test
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Read base_exception/tests/common.py and inspect how the decorator package invokes the decorated test. The issue provides a reproduction showing the test body is skipped and a possible fix that calls the function inside the decorator. Update the helper and run its affected tests; done means the test body executes and expected BaseExceptionError handling still works.
Written by the indexing model from the issue text.
Description
Problem
swallow_base_exception_error in base_exception/tests/common.py (18.0) never runs the test it decorates:
@decorator
def swallow_base_exception_error(func, self):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except BaseExceptionError:
return None
return wrapper
With decorator, the caller's return value is the result of the decorated call. This caller returns wrapper without calling it, so the test method returns a function object and its body is skipped. The test is then reported as passed.
Reproduction
With the decorator package shipped in the official odoo:18.0 image (5.1.1):
from decorator import decoratorx as decorator
@decorator
def swallow(func, self):
def wrapper(*a, **k):
try:
return func(*a, **k)
except ValueError:
return None
return wrapper
class T:
@swallow
def test(self):
print("BODY RAN")
raise AssertionError("fail inside")
print(T().test())
# <function swallow.<locals>.wrapper at 0x...> ("BODY RAN" is never printed)
Impact
Tests decorated with it pass without running any of their assertions. For example, several tests in sale_exception (OCA/sale-workflow#4255) and purchase_exception / purchase_request_exception (OCA/purchase-workflow#3012) use it.
Possible fix
Call the function inside the caller:
@decorator
def swallow_base_exception_error(func, self):
try:
return func(self)
except BaseExceptionError:
return None
With that, the decorated tests start running again, so some may need adjusting. A test that stops at the first BaseExceptionError also skips its remaining assertions. Asserting the error explicitly where it is expected may be safer than swallowing it for the whole test.
I found this while adapting hr_expense_exception (OCA/hr-expense#388, fix in OCA/hr-expense#391). That PR checks the error explicitly instead of using this helper.
- Dominant language
- Python
- Stars
- 960
- Forks
- 1.7k
- Avg merge
- 5d 23h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OCA/server-tools
-
dataclasses and python > 3.7Possibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OCA/server-tools#3859 ·
Maintainers usually reply within 1 day
-
When tracking Json fields an error pops in v19Possibly taken @xecanto claimed this 22 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OCA/server-tools#3796 ·
Maintainers usually reply within 1 day
-
[17.0] auto_backup: Cron: Database backup failed, UnicodeDecodeError: utf-8 codec can't decode byte 0x8b in position 690: invalid start bytePossibly taken @xecanto claimed this 33 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
OCA/server-tools#3768 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 65/100
OCA/server-tools#3368 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
OCA/server-tools#3139 · 1 comment ·
Maintainers usually reply within 1 day
All issues in OCA/server-tools
Similar issues
-
plot_graph crashes when a mesh node has no m2m edgePossibly taken @tygvi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
mllam/neural-lam#883 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement possible-duplicate
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
AOSSIE-Org/PictoPy#1715 · 2 comments ·
Maintainers usually reply within 6 days
-
SQLite connector omits generated columns from the catalog, and drops relationships sourced on themOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NVIDIA/auto-ontology#511 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ethereum/execution-specs#3996 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cpp-best-practices/project_validator#267 ·
Maintainers usually reply within 1 day