diff options
-rwxr-xr-x | scripts/oe-selftest | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest index f3865e4e81..bd9cbe0826 100755 --- a/scripts/oe-selftest +++ b/scripts/oe-selftest | |||
@@ -553,6 +553,7 @@ def main(): | |||
553 | 553 | ||
554 | def buildResultClass(args): | 554 | def buildResultClass(args): |
555 | """Build a Result Class to use in the testcase execution""" | 555 | """Build a Result Class to use in the testcase execution""" |
556 | import site | ||
556 | 557 | ||
557 | class StampedResult(unittest.TextTestResult): | 558 | class StampedResult(unittest.TextTestResult): |
558 | """ | 559 | """ |
@@ -568,26 +569,41 @@ def buildResultClass(args): | |||
568 | 569 | ||
569 | def startTestRun(self): | 570 | def startTestRun(self): |
570 | """ Setup coverage before running any testcase """ | 571 | """ Setup coverage before running any testcase """ |
572 | |||
573 | # variable holding the coverage configuration file allowing subprocess to be measured | ||
574 | self.coveragepth = None | ||
575 | |||
576 | # indicates the system if coverage is currently installed | ||
577 | self.coverage_installed = True | ||
578 | |||
571 | if args.coverage or args.coverage_source or args.coverage_include or args.coverage_omit: | 579 | if args.coverage or args.coverage_source or args.coverage_include or args.coverage_omit: |
572 | try: | 580 | try: |
573 | # check if user can do coverage | 581 | # check if user can do coverage |
574 | import coverage | 582 | import coverage |
575 | log.info("Coverage is enabled") | ||
576 | |||
577 | # In case the user has not set the variable COVERAGE_PROCESS_START, | ||
578 | # create a default one and export it. The COVERAGE_PROCESS_START | ||
579 | # value indicates where the coverage configuration file resides | ||
580 | # More info on https://pypi.python.org/pypi/coverage | ||
581 | if not os.environ.get('COVERAGE_PROCESS_START'): | ||
582 | os.environ['COVERAGE_PROCESS_START'] = coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, args.coverage_include, args.coverage_omit) | ||
583 | |||
584 | self.coverage_installed = True | ||
585 | except: | 583 | except: |
586 | log.warn('\n'.join(["python coverage is not installed", | 584 | log.warn('\n'.join(["python coverage is not installed", |
587 | "Make sure your coverage takes into account sub-process", | 585 | "Make sure your coverage takes into account sub-process", |
588 | "More info on https://pypi.python.org/pypi/coverage"])) | 586 | "More info on https://pypi.python.org/pypi/coverage"])) |
589 | self.coverage_installed = False | 587 | self.coverage_installed = False |
590 | 588 | ||
589 | if self.coverage_installed: | ||
590 | log.info("Coverage is enabled") | ||
591 | |||
592 | # In case the user has not set the variable COVERAGE_PROCESS_START, | ||
593 | # create a default one and export it. The COVERAGE_PROCESS_START | ||
594 | # value indicates where the coverage configuration file resides | ||
595 | # More info on https://pypi.python.org/pypi/coverage | ||
596 | if not os.environ.get('COVERAGE_PROCESS_START'): | ||
597 | os.environ['COVERAGE_PROCESS_START'] = coverage_setup(args.run_tests, args.run_all_tests, args.coverage_source, args.coverage_include, args.coverage_omit) | ||
598 | |||
599 | # Use default site.USER_SITE and write corresponding config file | ||
600 | site.ENABLE_USER_SITE = True | ||
601 | if not os.path.exists(site.USER_SITE): | ||
602 | os.makedirs(site.USER_SITE) | ||
603 | self.coveragepth = os.path.join(site.USER_SITE, "coverage.pth") | ||
604 | with open(self.coveragepth, 'w') as cps: | ||
605 | cps.write('import sys,site; sys.path.extend(site.getsitepackages()); import coverage; coverage.process_startup();') | ||
606 | |||
591 | def stopTestRun(self): | 607 | def stopTestRun(self): |
592 | """ Report coverage data after the testcases are run """ | 608 | """ Report coverage data after the testcases are run """ |
593 | 609 | ||
@@ -599,8 +615,14 @@ def buildResultClass(args): | |||
599 | 615 | ||
600 | log.info("Coverage Report") | 616 | log.info("Coverage Report") |
601 | log.info("===============") | 617 | log.info("===============") |
602 | 618 | try: | |
603 | coverage_report() | 619 | coverage_report() |
620 | # remove the pth file | ||
621 | finally: | ||
622 | try: | ||
623 | os.remove(self.coveragepth) | ||
624 | except OSError: | ||
625 | log.warn("Expected temporal file from coverage is missing, ignoring removal.") | ||
604 | 626 | ||
605 | return StampedResult | 627 | return StampedResult |
606 | 628 | ||