diff options
| author | Richard Mathot <rim@odoo.com> | 2017-10-03 13:14:16 +0200 |
|---|---|---|
| committer | Richard Mathot <rim@odoo.com> | 2017-10-03 14:29:01 +0200 |
| commit | e2349f45469e7075793a8da1ec78ddb3037ba4d5 (patch) | |
| tree | cf50afe0ee96cca8d4448ecb47008713daf91547 | |
| parent | 489245a5ee90a1a1350302b8e4af1e7b7b340e99 (diff) | |
[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
| -rw-r--r-- | odoo/modules/module.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/odoo/modules/module.py b/odoo/modules/module.py index af2b28883c4..15f4aae9a50 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -432,12 +432,19 @@ def get_test_modules(module): modpath = 'odoo.addons.' + module try: 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: - # If module has no `tests` sub-module, no problem. - if not pycompat.text_type(e).startswith(u'No module named'): - _logger.exception('Can not `import %s`.', module) + _logger.exception('Can not `import %s`.', module) return [] - if hasattr(mod, 'fast_suite') or hasattr(mod, 'checks'): _logger.warn( "Found deprecated fast_suite or checks attribute in test module " |
