[OE-core] [PATCH v2 2/2] scripts/oe-selftest: Use site.USER_SITE to run coverage configuration code for sub-process

Christopher Larson clarson at kergoth.com
Thu Feb 18 03:03:16 UTC 2016


On Wed, Feb 17, 2016 at 2:57 PM <humberto.ibarra.lopez at intel.com> wrote:

> From: Humberto Ibarra <humberto.ibarra.lopez at intel.com>
>
> Coverage in oe-selftest currently requires to create or modify
> a sitecustomize.py file according the coverage tool setup instructions
> (http://coverage.readthedocs.org/). This file has to be located in
> the system's python folder, which is not a good solution since this
> folder is not accesible to non-privileged users.
>
> The best solution so far is to create this file in the home directory.
> This is implemented by creating the temporal file in the user site
> default folder.
>
> [Yocto #8930]
>
> Signed-off-by: Humberto Ibarra <humberto.ibarra.lopez at intel.com>
> ---
>  scripts/oe-selftest | 46 ++++++++++++++++++++++++++++++++++------------
>  1 file changed, 34 insertions(+), 12 deletions(-)
>
> diff --git a/scripts/oe-selftest b/scripts/oe-selftest
> index f3865e4..25ca632 100755
> --- a/scripts/oe-selftest
> +++ b/scripts/oe-selftest
> @@ -553,6 +553,7 @@ def main():
>
>  def buildResultClass(args):
>      """Build a Result Class to use in the testcase execution"""
> +    import site
>
>      class StampedResult(unittest.TextTestResult):
>          """
> @@ -568,26 +569,41 @@ def buildResultClass(args):
>
>          def startTestRun(self):
>              """ Setup coverage before running any testcase """
> +
> +            # variable holding the coverage configuration file allowing
> subprocess to be measured
> +            self.coveragepth = None
> +
> +            # indicates the system if coverage is currently installed
> +            self.coverage_installed = True
> +
>              if args.coverage or args.coverage_source or
> args.coverage_include or args.coverage_omit:
>                  try:
>                      # check if user can do coverage
>                      import coverage
> -                    log.info("Coverage is enabled")
> -
> -                    # In case the user has not set the variable
> COVERAGE_PROCESS_START,
> -                    # create a default one and export it. The
> COVERAGE_PROCESS_START
> -                    # value indicates where the coverage configuration
> file resides
> -                    # More info on https://pypi.python.org/pypi/coverage
> -                    if not os.environ.get('COVERAGE_PROCESS_START'):
> -                        os.environ['COVERAGE_PROCESS_START'] =
> coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source,
> args.coverage_include, args.coverage_omit)
> -
> -                    self.coverage_installed = True
>                  except:
>                      log.warn('\n'.join(["python coverage is not
> installed",
>                          "Make sure your coverage takes into account
> sub-process",
>                          "More info on
> https://pypi.python.org/pypi/coverage"]))
>                      self.coverage_installed = False
>
> +                if self.coverage_installed:
> +                    log.info("Coverage is enabled")
> +
> +                # In case the user has not set the variable
> COVERAGE_PROCESS_START,
> +                # create a default one and export it. The
> COVERAGE_PROCESS_START
> +                # value indicates where the coverage configuration file
> resides
> +                # More info on https://pypi.python.org/pypi/coverage
> +                if not os.environ.get('COVERAGE_PROCESS_START'):
> +                    os.environ['COVERAGE_PROCESS_START'] =
> coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source,
> args.coverage_include, args.coverage_omit)
> +
> +                # Use default site.USER_SITE and write corresponding
> config file
> +                site.ENABLE_USER_SITE = True
> +                if not os.path.exists(site.USER_SITE):
> +                    os.makedirs(site.USER_SITE)
> +                self.coveragepth = os.path.join(site.USER_SITE,
> "coverage.pth")
> +                with open(self.coveragepth, 'w') as cps:
> +                    cps.write('import sys,site;
> sys.path.extend(site.getsitepackages()); import coverage;
> coverage.process_startup();')
> +
>          def stopTestRun(self):
>              """ Report coverage data after the testcases are run """
>
> @@ -599,8 +615,14 @@ def buildResultClass(args):
>
>                  log.info("Coverage Report")
>                  log.info("===============")
> -
> -                coverage_report()
> +                try:
> +                    coverage_report()
> +                    # remove the pth file
> +                finally:
> +                    try:
> +                        os.remove(self.coveragepth)
> +                    except OSError:
> +                        pass
>

I didn't notice this before, but if there's a legitimate failure to remove
the file, resulting in it still being in the user's site area, I doubt you
want to suppress such a failure. If you're specifically suppressing a
removal of a file which is already missing (though I don't know how you'd
get into that state), then you'd probably want to check errno to cover that
case. If not, then I think you should at least display a warning/error.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/openembedded-core/attachments/20160218/ee1c3333/attachment-0002.html>


More information about the Openembedded-core mailing list