Bug 11620

Summary: oe-selftest: fails with a traceback if python git module not installed
Product: [QA/Testing] Build Testing Reporter: Paul Eggleton <bluelightning>
Component: generalAssignee: Leonardo Sandoval Gonzalez <leonardo.sandoval.gonzalez>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: High CC: anibal.limon, jose.perez.carranza, mikko.ylinen, richard.purdie
Version: unspecified   
Target Milestone: 2.4 M1   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: Regression (Used to work)
Verified: Documentation change: Don't know

Description Paul Eggleton 2017-06-07 08:37:58 UTC
If you run oe-selftest on a machine where python3-git (or python3-GitPython on some distributions) is not installed you get the following traceback:

----------------------- snip -----------------------
$ oe-selftest --run-tests bblayers devtool recipetool
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
    __import__(name)
  File "/home/paul/poky/poky/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py", line 4, in <module>
    from git import Repo
ImportError: No module named 'git'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/paul/poky/poky/scripts/oe-selftest", line 70, in <module>
    ret = main()
  File "/home/paul/poky/poky/scripts/oe-selftest", line 57, in main
    results = args.func(logger, args)
  File "/home/paul/poky/poky/meta/lib/oeqa/selftest/context.py", line 214, in run
    rc = self._internal_run(logger, args)
  File "/home/paul/poky/poky/meta/lib/oeqa/selftest/context.py", line 175, in _internal_run
    self.tc.loadTests(self.module_paths, **self.tc_kwargs['load'])
  File "/home/paul/poky/poky/meta/lib/oeqa/core/context.py", line 51, in loadTests
    self.suites = self.loader.discover()
  File "/home/paul/poky/poky/meta/lib/oeqa/core/loader.py", line 270, in discover
    pattern='*.py', top_level_dir=path)
  File "/usr/lib/python3.4/unittest/loader.py", line 264, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/usr/lib/python3.4/unittest/loader.py", line 349, in _find_tests
    namespace=namespace)
  File "/usr/lib/python3.4/unittest/loader.py", line 316, in _find_tests
    yield _make_failed_import_test(name, self.suiteClass)
  File "/usr/lib/python3.4/unittest/loader.py", line 25, in _make_failed_import_test
    suiteClass)
  File "/home/paul/poky/poky/meta/lib/oeqa/core/loader.py", line 23, in _make_failed_test
    raise exception
ImportError: Failed to import test module: oelib.buildhistory
Traceback (most recent call last):
  File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
    __import__(name)
  File "/home/paul/poky/poky/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py", line 4, in <module>
    from git import Repo
ImportError: No module named 'git'
----------------------- snip -----------------------

Test modules that fail due to ImportError should generate a warning during startup rather than causing oe-selftest to error out with an ugly traceback.
Comment 1 Leonardo Sandoval Gonzalez 2017-06-07 14:43:04 UTC
Patch sent for review: http://lists.openembedded.org/pipermail/openembedded-core/2017-June/137665.html
Comment 2 Leonardo Sandoval Gonzalez 2017-06-08 13:54:22 UTC
Merge in poky with hash: 4a7612c7a12b9a381fb8343ba9586272b889fc15