Skip to content
Snippets Groups Projects
Unverified Commit e2349f45 authored by Richard Mathot's avatar Richard Mathot
Browse files

[FIX] odoo: bad imports in tests don't fail silently anymore

Before this fix, you can break a test class by simply adding an
incorrect import like this:
`from gloubiboulga import Casimir`
--> No error message, the test is simply not run

This is due to the fact that we want to ignore ImportError's... only
when there is no `.tests` submodules (actually, we ignored them all!)

This commit fixes the condition and re-enables error logging when tests
actually encounter ImportErrors
parent 489245a5
No related branches found
No related tags found
No related merge requests found
...@@ -432,12 +432,19 @@ def get_test_modules(module): ...@@ -432,12 +432,19 @@ def get_test_modules(module):
modpath = 'odoo.addons.' + module modpath = 'odoo.addons.' + module
try: try:
mod = importlib.import_module('.tests', modpath) mod = importlib.import_module('.tests', modpath)
except ImportError as e: # will also catch subclass ModuleNotFoundError of P3.6
# Hide ImportErrors on `tests` sub-module, but display other exceptions
if pycompat.PY2:
if e.message.startswith('No module named') and e.message.endswith("tests"):
return []
else:
if e.name == modpath + '.tests' and e.msg.startswith('No module named'):
return []
_logger.exception('Can not `import %s`.', module)
return []
except Exception as e: except Exception as e:
# If module has no `tests` sub-module, no problem. _logger.exception('Can not `import %s`.', module)
if not pycompat.text_type(e).startswith(u'No module named'):
_logger.exception('Can not `import %s`.', module)
return [] return []
if hasattr(mod, 'fast_suite') or hasattr(mod, 'checks'): if hasattr(mod, 'fast_suite') or hasattr(mod, 'checks'):
_logger.warn( _logger.warn(
"Found deprecated fast_suite or checks attribute in test module " "Found deprecated fast_suite or checks attribute in test module "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment