Skip to content

[18.0][FIX] base_exception: make the swallow test helper run the test - #3793

Open
SparkDrago05 wants to merge 1 commit into
OCA:18.0from
SparkDrago05:18.0-fix-base_exception-swallow-helper
Open

SparkDrago05 wants to merge 1 commit into
OCA:18.0from
SparkDrago05:18.0-fix-base_exception-swallow-helper

Conversation

@SparkDrago05

Copy link
Copy Markdown

Fixes #3784.

swallow_base_exception_error returned its inner wrapper without calling it, so every test it decorated passed without running its body.

Changes

  • swallow_base_exception_error now calls the test. The decorated tests in other modules run again.
  • New expect_base_exception_error context manager. It checks that BaseExceptionError is raised, but without the savepoint rollback of assertRaises, so the exceptions stored by the detection can still be checked afterwards.
  • The six base_exception tests that used the swallow helper now use it, and their bodies run to the end.

When the helper is only fixed, each of those six tests stops at its first BaseExceptionError. I instrumented it to confirm: all six stopped at the first confirm or detect call, so none of their later assertions ever ran.

Since #3590, a newly detected exception raises BaseExceptionError before _check_exception() can raise ValidationError. The old assertRaises(ValidationError) expectations therefore never matched what the code does today. Nobody noticed because the tests didn't run. They now expect BaseExceptionError, and the remaining checks (exception_ids, exceptions_summary, ignoring, blocking, state after ignoring) all run and pass.

Tested

On Odoo 18.0 (official image):

  • base_exception: 0 failed, 0 error(s) of 14 tests.
  • sale_exception (sale-workflow 18.0, a downstream user of the helper) with this branch: 0 failed, 0 error(s) of 8 tests.

ruff and pylint-odoo (mandatory) are clean.

cc @gal-adhoc

swallow_base_exception_error returned its inner wrapper without calling
it, so every test it decorated passed without running its body.

- Call the test inside the helper, so tests in other modules that use
  it run again.
- Add expect_base_exception_error, which checks that BaseExceptionError
  is raised without the savepoint rollback of assertRaises, so the
  exceptions stored by the detection can still be checked.
- Rewrite the six decorated base_exception tests with it. Their bodies
  now run to the end. Since the rollback change, a detected exception
  raises BaseExceptionError instead of ValidationError, so their
  expectations are updated.

Fixes OCA#3784

Signed-off-by: SparkDrago05 <huzaifa.farooq05@gmail.com>
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @sebastienbeau, @hparfr,
some modules you are maintaining are being modified, check this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants