Skip to content

tests: add support for native-specific .exp test output files #17882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2025

Conversation

dpgeorge
Copy link
Member

Summary

There are currently a few tests that are excluded when using the native emitter because they test printing of exception tracebacks, which includes line numbers. And the native emitter doesn't store line numbers, so gets these tests wrong.

But we'd still like to run these tests using the native emitter, because they test useful things even if the line number info is not in the traceback (eg that threads which crash print out their exception).

This PR adds support for native-specific .exp files, which are of the form <test>.py.exp.native. If such an .exp file exists then it take precedence over any normal <test>.py.exp file. (Actually, the implementation is general enough that it also supports <test>py.exp.bytecode as well, if bytecode ever needs a specific exp file.)

In this PR:

  • support for run-tests.py to look for <test>.py.exp.native files (a very simple change)
  • adding of a few such .exp.native files to tests that need them
  • remove excluded native tests from run-tests.py
  • tweak a few other tests so they can run with the native emitter

Testing

Tested locally on PYBD_SF6, RPI_PICO2_W, ESP32 and unix port. There were no regressions, and the new tests (now no longer excluded) pass with the native emitter.

Will also be tested by CI.

Trade-offs and Alternatives

  • Could change the test so it doesn't rely on line numbers, but that really defeats the purpose of some of these tests, which aim to test line numbering.
  • Could make the .exp have special regex pattern matching, but again that would mean the actual line number for the bytecode emitter is not tested.
  • Could make the native emitter support line numbers in tracebacks... but that's very difficult!

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Aug 11, 2025
@dpgeorge dpgeorge requested a review from projectgus August 11, 2025 04:39
@Josverl
Copy link
Contributor

Josverl commented Aug 11, 2025

Minor tidbit: To me the naming <test>.py.native.exp would make more sense, as that keeps the extension consistent.

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! Although also have a slight preference for filename.native.exp rather than the other way around.

@dpgeorge dpgeorge force-pushed the tests-add-native-exp-files branch from ec74903 to cdaca1e Compare August 13, 2025 02:03
@dpgeorge
Copy link
Member Author

Thanks for the reviews. I've now changed the file pattern to <test>.py.native.exp as suggested.

Copy link

codecov bot commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (0cb2c69) to head (a279c64).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17882   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22295    22295           
=======================================
  Hits        21936    21936           
  Misses        359      359           

☔ 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.

There are currently a few tests that are excluded when using the native
emitter because they test printing of exception tracebacks, which includes
line numbers.  And the native emitter doesn't store line numbers, so gets
these tests wrong.

But we'd still like to run these tests using the native emitter, because
they test useful things even if the line number info is not in the
traceback (eg that threads which crash print out their exception).

This commit adds support for native-specific .exp files, which are of the
form `<test>.py.native.exp`.  If such an .exp file exists then it take
precedence over any normal `<test>.py.exp` file.

(Actually, the implementation here is general enough that it also supports
`<test>.py.bytecode.exp` as well, if bytecode ever needs a specific exp
file.)

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

The test semantics remain the same.

Signed-off-by: Damien George <damien@micropython.org>
So that the test can run the same on all targets when used with the native
emitter.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the tests-add-native-exp-files branch from cdaca1e to a279c64 Compare August 14, 2025 14:37
@dpgeorge dpgeorge merged commit a279c64 into micropython:master Aug 14, 2025
32 of 33 checks passed
@dpgeorge dpgeorge deleted the tests-add-native-exp-files branch August 14, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Relates to tests/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants