diff --git a/extmod/modure.c b/extmod/modure.c
index 0d5330cb548e41e3e21937b53d579a5576674923..8a60207053054f3f9fa90999392fe5ba6ec6fbd4 100644
--- a/extmod/modure.c
+++ b/extmod/modure.c
@@ -382,6 +382,7 @@ STATIC const mp_obj_type_t re_type = {
 };
 
 STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
+    (void)n_args;
     const char *re_str = mp_obj_str_get_str(args[0]);
     int size = re1_5_sizecode(re_str);
     if (size == -1) {
@@ -389,18 +390,22 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
     }
     mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size);
     o->base.type = &re_type;
+    #if MICROPY_PY_URE_DEBUG
     int flags = 0;
     if (n_args > 1) {
         flags = mp_obj_get_int(args[1]);
     }
+    #endif
     int error = re1_5_compilecode(&o->re, re_str);
     if (error != 0) {
 error:
         mp_raise_ValueError("Error in regex");
     }
+    #if MICROPY_PY_URE_DEBUG
     if (flags & FLAG_DEBUG) {
         re1_5_dumpcode(&o->re);
     }
+    #endif
     return MP_OBJ_FROM_PTR(o);
 }
 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile);
@@ -440,7 +445,9 @@ STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = {
     #if MICROPY_PY_URE_SUB
     { MP_ROM_QSTR(MP_QSTR_sub), MP_ROM_PTR(&mod_re_sub_obj) },
     #endif
+    #if MICROPY_PY_URE_DEBUG
     { MP_ROM_QSTR(MP_QSTR_DEBUG), MP_ROM_INT(FLAG_DEBUG) },
+    #endif
 };
 
 STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table);
@@ -455,7 +462,9 @@ const mp_obj_module_t mp_module_ure = {
 
 #define re1_5_fatal(x) assert(!x)
 #include "re1.5/compilecode.c"
+#if MICROPY_PY_URE_DEBUG
 #include "re1.5/dumpcode.c"
+#endif
 #include "re1.5/recursiveloop.c"
 #include "re1.5/charclass.c"
 
diff --git a/ports/unix/mpconfigport_coverage.h b/ports/unix/mpconfigport_coverage.h
index b2f1d6e88ea599bb4ea580cce105db3fa16ee044..afd364649077cf1860762774eb86d92e8d2bd487 100644
--- a/ports/unix/mpconfigport_coverage.h
+++ b/ports/unix/mpconfigport_coverage.h
@@ -50,6 +50,7 @@
 #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
 #define MICROPY_PY_IO_BUFFEREDWRITER (1)
 #define MICROPY_PY_IO_RESOURCE_STREAM (1)
+#define MICROPY_PY_URE_DEBUG           (1)
 #define MICROPY_PY_URE_MATCH_GROUPS    (1)
 #define MICROPY_PY_URE_MATCH_SPAN_START_END (1)
 #define MICROPY_PY_URE_SUB             (1)
diff --git a/py/mpconfig.h b/py/mpconfig.h
index e8f60bd77ffdcb8daa26161f991a1e2c87ad7697..57dec3cf266b13fea4b2add48c4cf9b96d3d0e63 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -1259,6 +1259,10 @@ typedef double mp_float_t;
 #define MICROPY_PY_URE (0)
 #endif
 
+#ifndef MICROPY_PY_URE_DEBUG
+#define MICROPY_PY_URE_DEBUG (0)
+#endif
+
 #ifndef MICROPY_PY_URE_MATCH_GROUPS
 #define MICROPY_PY_URE_MATCH_GROUPS (0)
 #endif
diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py
index cfb264bb6d2900e075100eac1dba6b8a350617f0..621fc8d50eacea211a75ada14a07f1c3a5636f84 100644
--- a/tests/extmod/ure_debug.py
+++ b/tests/extmod/ure_debug.py
@@ -1,7 +1,8 @@
 # test printing debugging info when compiling
 try:
     import ure
-except ImportError:
+    ure.DEBUG
+except (ImportError, AttributeError):
     print("SKIP")
     raise SystemExit