Skip to content

tests: Fix more tests failing with terse error messages.#19324

Open
agatti wants to merge 3 commits into
micropython:masterfrom
agatti:terse-tests
Open

tests: Fix more tests failing with terse error messages.#19324
agatti wants to merge 3 commits into
micropython:masterfrom
agatti:terse-tests

Conversation

@agatti

@agatti agatti commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes all tests appearing in the Unix port's standard variant when built with terse error messages.

As mentioned in #17707, there still are tests faiing with this specific configuration. The commits in this PR attempt to address this situation and add a new CI job to routinely test the Unix port to make sure new tests won't depend on strings that may change depending on the error reporting level.

There are still some tests that fail with terse messages, but they only occur on the coverage variant. Fixing them is something I'll have in another PR since they involve messing with C code as half of those failures are in ports/unix/coverage.c. Fixing the Python ones wouldn't really help CI-wise until the native ones are updated anyway.

This fixes #17707.

Testing

This is going to be tested by the new CI job, added as part of this PR.

Trade-offs and Alternatives

Since this adds a new CI job to the list, CI runs may get a tiny bit slower. The Unix/standard job usually takes around 30 seconds or so to run so its impact shouldn't really be felt during regular development.

Generative AI

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

@agatti agatti added the tests Relates to tests/ directory in source label Jun 9, 2026
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

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

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

☔ View full report in Codecov by Harness.
📢 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.

Comment thread tools/ci.sh Outdated
}

function ci_unix_standard_terse_run_tests {
MICROPY_TEST_TIMEOUT=60 make -C ports/unix VARIANT=standard test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think the timeout needs to be increased here. Best to leave it at the default if possible.

@dpgeorge

dpgeorge commented Jun 9, 2026

Copy link
Copy Markdown
Member

Did you see 9ecdeb6 ? Maybe some of the tests here can be added to that list if they really need to check the exact form of the error string.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Code size report:

Reference:  samd/mphalport: Run events at least once in mp_hal_delay_ms. [af38ee1]
Comparison: tools/ci.sh: Add new Unix target with terse error messages. [merge of b4acf3b]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@agatti

agatti commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Did you see 9ecdeb6 ? Maybe some of the tests here can be added to that list if they really need to check the exact form of the error string.

I didn't know of such a thing. Looking at the modified tests in this PR I can definitely see cmdline/repl_paste being put there, as VFS and SSL/TLS failures are probably something worth testing in all cases anyway.

Out of the extra tests that fail on coverage (basics/string_tstring_constructor1.py, micropython/builtin_tstring.py, misc/sys_settrace_features.py, ports/unix/extra_coverage.py), I can probably pre-emptively put misc/sys_settrace_features.py in there too as part of this PR. ports/unix/extra_coverage.py depends on native code that needs to be modified so that will have to wait, and the two remaining tstring tests won't work on standard variants anyway but can be fixed relatively easily so it may help to always run them.

@dpgeorge

dpgeorge commented Jun 9, 2026

Copy link
Copy Markdown
Member

I should say that the general direction of this PR is good: adding CI to test terse error message builds, and fixing related things up. Just need to tune it to get it passing all the existing CI.

@agatti

agatti commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I've updated the PR to make it work. tests/extmod/vfs_blockdev_invalid.py had to be updated quite a bit but it should still work in low memory conditions. I'll see what octoprobe will say about that :)

This commit updates `extmod/ssl_keycert`,
`extmod/tls_sslcontext_ciphers`, and `extmod/vfs_blockdev_invalid` tests
to also pass even if the interpreter was built with terse error
messages.

Originally the tests assumed the error messages level was always higher
than `MICROPY_ERROR_REPORTING_TERSE`, and thus expected a particular
string pattern to appear in certain errors' output.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Comment thread tests/run-tests.py Outdated
error_reporting_tests_to_skip["terse"] = error_reporting_tests_to_skip["none"]
error_reporting_tests_to_skip["terse"] = error_reporting_tests_to_skip["none"] + (
"cmdline/repl_paste.py",
"misc/sys_settrace_features.py",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These probably need to be skipped when error reporting is "none", so could just go in the tuple above?

@agatti agatti Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's true, but on the other hand there's no build testing things with said error reporting level, so adding things to terse should still be reasonable in practice.

In the meantime I'll still put those in the none list. I guess I'll need to have a go at building unix/standard with that reporting level to see which tests need to be added to the list then. That'll be another PR.

Edit: well, it doesn't even build. Building the Unix port with make -j8 VARIANT=standard CFLAGS_EXTRA="-DMICROPY_ERROR_REPORTING=MICROPY_ERROR_REPORTING_NONE" MICROPY_ROM_TEXT_COMPRESSION=0 yields this:

...
In file included from ../../py/emitnx64.c:16:
../../py/emitnative.c:207:13: error: ‘vtype_to_qstr’ defined but not used [-Werror=unused-function]
  207 | static qstr vtype_to_qstr(vtype_kind_t vtype) {
      |             ^~~~~~~~~~~~~
...
../../py/nativeglue.c:323:5: error: ‘mp_raise_msg’ undeclared here (not in a function)
  323 |     mp_raise_msg,
      |     ^~~~~~~~~~~~
../../py/nativeglue.c:323:5: note: ‘mp_raise_msg’ is a function-like macro and might be used incorrectly

Fixing the build errors makes tests/feature_check/target_info.py fail too :(

Anyway, things build and run with this:

diff --git i/py/emitnative.c w/py/emitnative.c
index 6cf01dcab..781aacf74 100644
--- i/py/emitnative.c
+++ w/py/emitnative.c
@@ -204,6 +204,7 @@ typedef enum {
     VTYPE_BUILTIN_CAST = 0x70 | MP_NATIVE_TYPE_OBJ,
 } vtype_kind_t;
 
+#if MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_NONE
 static qstr vtype_to_qstr(vtype_kind_t vtype) {
     switch (vtype) {
         case VTYPE_PYOBJ:
@@ -227,6 +228,7 @@ static qstr vtype_to_qstr(vtype_kind_t vtype) {
             return MP_QSTR_None;
     }
 }
+#endif
 
 typedef struct _stack_info_t {
     vtype_kind_t vtype;
diff --git i/py/nativeglue.c w/py/nativeglue.c
index e4aa635cf..e9164ee4c 100644
--- i/py/nativeglue.c
+++ w/py/nativeglue.c
@@ -320,7 +320,11 @@ const mp_fun_table_t mp_fun_table = {
     gc_realloc,
     mp_printf,
     mp_vprintf,
+    #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE
+    NULL,
+    #else
     mp_raise_msg,
+    #endif
     mp_obj_get_type,
     mp_obj_new_str,
     mp_obj_new_bytes,
diff --git i/tests/feature_check/target_info.py w/tests/feature_check/target_info.py
index ed91b27b7..35bb6b4ad 100644
--- i/tests/feature_check/target_info.py
+++ w/tests/feature_check/target_info.py
@@ -40,6 +40,6 @@ except NameError:
 try:
     (lambda: 0)(0)
 except TypeError as er:
-    error_reporting = {0: "none", 27: "terse", 54: "normal", 56: "detailed"}[len(er.value)]
+    error_reporting = {0: "none", 27: "terse", 54: "normal", 56: "detailed"}[len(er.value or '')]
 
 print(platform, arch, arch_flags, build, thread, float_prec, len("α") == 1, error_reporting)

and the list of failing tests is this: basics/deque_micropython.py, basics/generator_pend_throw.py, basics/int_64_basics.py, basics/subclass_native_exc_new.py, extmod/ssl_keycert.py, extmod/ssl_keycert_pkcs8.py, extmod/vfs_blockdev_invalid.py, float/math_fun.py, float/math_fun_special.py, extmod/cryptolib_aes128_ctr.py, extmod/ssl_cadata.py, micropython/import_mpy_invalid.py, micropython/import_mpy_native.py, micropython/viper_error.py, extmod/asyncio_cancel_self.py, extmod/tls_sslcontext_ciphers.py, stress/bytecode_limit.py, stress/qstr_limit.py, stress/qstr_limit_str_modulo.py, extmod/asyncio_gather_notimpl.py. PR coming up soon.

agatti added 2 commits June 9, 2026 15:04
This commit updates the list of tests to skip if the error message level
is less or equal to "terse", adding `cmdline/repl_paste` and
`misc/sys_settrace_features`.

For the former, in situations where space is at a premium usually the
REPL isn't enabled.  If it is, changes to its internals are usually
covered by other tests.

The latter, on the other hand, would require either a fundamentally
reworked test script, or modifying the test harness to cater for two
very different outputs set for a single test.  Using regular expressions
here won't help, as the changes involve block of lines rather than parts
of a single line at a time.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit adds a new CI target for the Unix port, which is the
`standard` variant being built with terse error messages.

Even though it won't cover all possible tests failing with terse error
messages (some occur only in the `coverage` build variant), this should
be a good start for preventing new tests to not assume a particular
error message level.

To make things automated, the new target is also added to the regular CI
jobs set in the Unix port's GitHub workflow file.

This closes micropython#17707.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@octoprobe-bot

Copy link
Copy Markdown

Octoprobe PR report

Test Tests
passed
Tests
skipped
Tests
xfailed
Tests
failed
format flash 10 9
run-tests.py 16537 2200 8 1
run-tests.py --via-mpy --emit native 16897 2860 19 4
run-tests.py --via-mpy 17485 2286 9
run-perfbench.py 436 15 2
run-natmodtests.py 629 148 2
run-tests.py --test-dirs=extmod_hardware 60 78 24
run-tests.py --test-dirs=extmod_hardware --emit-native 53 77 23
Total 52107 7673 87 5
Failures

Group: run-tests.py

Test esp32
0c30-
ESP32_C3_DEVKIT
esp32
5d21-
ESP32_DEVKIT
esp32
472b-
ESP32_S3_DEVKIT
esp32
1830-
LOLIN_C3_MINI
esp8266
2d2d-
LOLIN_D1_MINI
mimxrt
1133-
TEENSY40
nrf
3c2a-
ARDUINO_NANO_33
rp2
5334-
RPI_PICO2
rp2
5334-
RPI_PICO2-
RISCV
rp2
552b-
RPI_PICO2_W
rp2
5f2c-
RPI_PICO_W
rp2
6038-
RPI_PICO_W
samd
5f2a-
ADA_ITSYBITSY_M0
stm32
2b35-
NUCLEO_WB55
stm32
3a21-
PYBV11
stm32
3a21-
PYBV11-
DP
stm32
3a21-
PYBV11-
DP_THREAD
stm32
3a21-
PYBV11-
THREAD
extmod/socket_udp_nonblock.py pass pass pass pass pass skip skip skip skip pass pass FAIL skip skip skip skip skip skip

Group: run-tests.py --via-mpy --emit native

Test esp32
0c30-
ESP32_C3_DEVKIT
esp32
5c34-
ESP32_C3_DEVKIT
esp32
5d21-
ESP32_DEVKIT
esp32
472b-
ESP32_S3_DEVKIT
esp32
1830-
LOLIN_C3_MINI
esp8266
2d2d-
LOLIN_D1_MINI
mimxrt
1133-
TEENSY40
nrf
3c2a-
ARDUINO_NANO_33
rp2
5334-
RPI_PICO2
rp2
5334-
RPI_PICO2-
RISCV
rp2
552b-
RPI_PICO2_W
rp2
5f2c-
RPI_PICO_W
rp2
6038-
RPI_PICO_W
samd
5f2a-
ADA_ITSYBITSY_M0
stm32
2b35-
NUCLEO_WB55
stm32
3a21-
PYBV11
stm32
3a21-
PYBV11-
DP
stm32
3a21-
PYBV11-
DP_THREAD
stm32
3a21-
PYBV11-
THREAD
basics/int_big_mod.py pass pass pass pass pass FAIL pass pass pass pass pass pass pass pass pass pass pass pass pass
micropython/viper_ptr16_load_boundary.py pass pass pass pass pass skip pass pass pass pass pass pass pass FAIL pass pass pass pass pass
micropython/viper_ptr32_load_boundary.py pass pass pass pass pass skip pass pass pass pass pass pass pass FAIL pass pass pass pass pass
stress/qstr_limit.py pass pass pass pass pass skip pass pass pass pass pass pass pass FAIL pass pass pass pass pass

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.

Passing tests reported as failures with MICROPY_ERROR_REPORTING_TERSE

3 participants