Skip to content

Commit

Permalink
Coverage save atexit trial
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrussimon authored and gsfr committed Jan 30, 2018
1 parent 8314702 commit 37d58b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 8 additions & 10 deletions api/web/start.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import atexit
import json
import os
import traceback
Expand All @@ -7,20 +8,17 @@
# Start coverage before local module loading so their def and imports are counted
# http://coverage.readthedocs.io/en/coverage-4.2/faq.html
if os.environ.get("SCITRAN_RUNTIME_COVERAGE") == "true": # pragma: no cover - oh, the irony
import coverage
cov = coverage.coverage(source=["api"], data_file="/tmp/.coverage.integration-tests")

class CoverageSaveHandler(webapp2.RequestHandler):
def save_coverage(self):
print("Saving coverage")
cov.stop()
cov.save()
def save_coverage(cov):
print("Saving coverage")
cov.stop()
cov.save()

def start_coverage():
import coverage
print("Enabling code coverage")
cov = coverage.coverage(source=["api"], data_file="/tmp/.coverage.integration-tests")
cov.start()
from ..api import endpoints, route # pylint: disable=redefined-outer-name
endpoints.append(route('/api/save-coverage', CoverageSaveHandler, h='save_coverage', m=['POST']))
atexit.register(save_coverage, cov)

start_coverage()

Expand Down
5 changes: 3 additions & 2 deletions tests/bin/docker-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ clean_up() {
docker cp core-test-runner:/src/core/.coverage .coverage.unit-tests 2>/dev/null

# Save integration test coverage
docker exec core-test-service python -c 'import requests; requests.post("http://localhost/api/save-coverage")'
docker cp core-test-service:/tmp/.coverage.integration-tests ./ 2>/dev/null
docker stop core-test-service
docker wait core-test-service
docker cp core-test-service:/tmp/.coverage.integration-tests ./

# Combine unit/integ coverage and report/grenerate html
docker run --rm \
Expand Down

0 comments on commit 37d58b1

Please sign in to comment.