Commit 2563a46e authored by Godefroid Chapelle's avatar Godefroid Chapelle

run coverage should be explicit

register combine and report with atexit
parent 0a6d23e8
...@@ -24,9 +24,10 @@ eggs = ...@@ -24,9 +24,10 @@ eggs =
zc.recipe.egg zc.recipe.egg
coverage coverage
initialization = initialization =
import os import os.path
if 'COVERAGE_PROCESS_START' not in os.environ: os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('../../.coveragerc') from zc.buildout.testing import setup_coverage
if os.getenv('COVERAGE_PROCESS_START'): import coverage; coverage.process_startup() path_to_coveragerc = os.path.join('${buildout:directory}', '.coveragerc')
setup_coverage(path_to_coveragerc)
# Tests that can be run wo a network # Tests that can be run wo a network
[oltest] [oltest]
......
...@@ -297,15 +297,8 @@ def buildoutSetUp(test): ...@@ -297,15 +297,8 @@ def buildoutSetUp(test):
# way due to the trick above: # way due to the trick above:
os.mkdir('develop-eggs') os.mkdir('develop-eggs')
if os.getenv("COVERAGE_PROCESS_START"): path_to_coveragerc = os.getenv("COVERAGE_PROCESS_START", None)
# The user has requested subprocess code coverage. Since we will be changing if path_to_coveragerc is not None:
# directories, we need to make sure this path is absolute, which means
# we need to temporarily return to our starting directory.
os.chdir(here)
path_to_coveragerc = os.path.abspath(os.environ['COVERAGE_PROCESS_START'])
os.chdir(sample)
assert os.path.isfile(path_to_coveragerc), path_to_coveragerc
os.environ['COVERAGE_PROCESS_START'] = path_to_coveragerc
# Before we return to the current directory and destroy the # Before we return to the current directory and destroy the
# temporary working directory, we need to copy all the coverage files # temporary working directory, we need to copy all the coverage files
...@@ -641,3 +634,41 @@ def run_buildout_in_process(command='buildout'): ...@@ -641,3 +634,41 @@ def run_buildout_in_process(command='buildout'):
) )
command = ' '.join(command) command = ' '.join(command)
run_in_process(run_buildout, command) run_in_process(run_buildout, command)
def setup_coverage(path_to_coveragerc):
if 'RUN_COVERAGE' not in os.environ:
return
if not os.path.exists(path_to_coveragerc):
raise ValueError('coveragerc file %s does not exist.' % path_to_coveragerc)
os.environ['COVERAGE_PROCESS_START'] = path_to_coveragerc
rootdir = os.path.dirname(path_to_coveragerc)
def combine_report():
subprocess.call(
[
sys.executable, '-m', 'coverage', 'combine',
],
cwd=rootdir,
)
subprocess.call(
[
sys.executable, '-m', 'coverage', 'report',
],
cwd=rootdir,
)
if path_to_coveragerc:
try:
import coverage
print("Coverage configured with %s" % path_to_coveragerc)
if 'COVERAGE_REPORT' in os.environ:
import atexit
atexit.register(combine_report)
coverage.process_startup()
except ImportError:
print(
"You try to run coverage "
"but coverage is not installed in your environment."
)
sys.exit(1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment