revert coverage cmd order
add Process subclass to handle Process in coverage context (unittest)
This commit is contained in:
@@ -35,3 +35,5 @@ try: # pragma: no cover
|
||||
except PackageNotFoundError: # pragma: no cover
|
||||
warnings.warn('can not read dist.metadata["Name"], assuming local test context, setting it to <chacha_cicd_helper>')
|
||||
__Name__ = "chacha_cicd_helper"
|
||||
|
||||
from .coverage_tools import CoverageProcess
|
||||
|
||||
23
src/chacha_cicd_helper/coverage_tools.py
Normal file
23
src/chacha_cicd_helper/coverage_tools.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from coverage import Coverage
|
||||
from multiprocessing import Process
|
||||
import os
|
||||
|
||||
|
||||
class CoverageProcess(Process):
|
||||
def __init__(self, *args, config_file=None, **kwargs):
|
||||
self._config_file = config_file
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def run(self):
|
||||
if self._config_file:
|
||||
cov = Coverage(config_file=self._config_file, data_suffix=os.getpid(), auto_data=True)
|
||||
cov._warn_no_data = False
|
||||
cov.start()
|
||||
|
||||
try:
|
||||
super().run()
|
||||
finally:
|
||||
cov.stop()
|
||||
cov.save()
|
||||
else:
|
||||
super().run()
|
||||
@@ -64,8 +64,8 @@ class cl_unit_test(cl_helper_withresults_base):
|
||||
print("Test Finished")
|
||||
if cls.enable_coverage_check is True:
|
||||
cov.stop()
|
||||
cov.combine()
|
||||
cov.save()
|
||||
cov.combine()
|
||||
cov.html_report(directory=str(CoverageReportPath))
|
||||
cov.xml_report(outfile=str(CoverageReportPath / f"{cls.CoverageReportName}.xml"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user