Skip to content

tests: Change most uses of "raise" with 0 args to have 1 arg.#19245

Open
dpgeorge wants to merge 2 commits into
micropython:masterfrom
dpgeorge:tests-reduce-reraise
Open

tests: Change most uses of "raise" with 0 args to have 1 arg.#19245
dpgeorge wants to merge 2 commits into
micropython:masterfrom
dpgeorge:tests-reduce-reraise

Conversation

@dpgeorge
Copy link
Copy Markdown
Member

Summary

The native emitter cannot compile "raise" without exactly one argument. Some tests use raise-without-args and are
explicitly skipped with the native emitter, while others used it without being skipped and crash the device.

Two things to address that:

  • raise a NotImplementedError in the compiler instead of crashing/asserting
  • change the tests so most of them do not use raise-without-args, allowing more tests to run with the native emitter

The only remaining raise-with-0-args are in tests than specifically check this re-raise behaviour.

Testing

  • Ran the stm32-specific tests with the native emitter.
  • Ran the net_inet tests with the native emitter (on unix port).
  • CI

A coverage test is added for the new exception.

Trade-offs and Alternatives

This adds a bit of code size for the new exception in the native emitter, but that's a lot better than crashing/asserting without a good indication of why.

Generative AI

I did not use generative AI tools when creating this PR.

dpgeorge added 2 commits May 19, 2026 22:27
The native emitter cannot generate code for "raise" (re-raising) or
"raise x from y" (exception chaining).  Trying to generate such code can
happen in normal programs, so raise an NotImplementedError instead of using
an assert (that won't even be enabled in most production builds).

And add a coverage test for this new exception.

Signed-off-by: Damien George <damien@micropython.org>
This allows these tests to run with the native emitter.

The only remaining raise-with-0-args are in tests than specifically check
this re-raise behaviour.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added py-core Relates to py/ directory in source tests Relates to tests/ directory in source labels May 19, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (1c63211) to head (b66404d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19245   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files         176      176           
  Lines       22845    22846    +1     
=======================================
+ Hits        22497    22498    +1     
  Misses        348      348           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

Code size report:

Reference:  github/workflows: Bump actions/github-script from 8 to 9. [1c63211]
Comparison: tests: Change most uses of "raise" with 0 args to have 1 arg. [merge of b66404d]
  mpy-cross:  +160 +0.042% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:   +16 +0.002% standard
      stm32:   +16 +0.004% PYBV10
      esp32:   +16 +0.001% ESP32_GENERIC
     mimxrt:   +16 +0.004% TEENSY40
        rp2:   +16 +0.002% RPI_PICO_W
       samd:   +16 +0.006% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:   +26 +0.006% VIRT_RV32

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

Labels

py-core Relates to py/ directory in source tests Relates to tests/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant