From 5118f91c777e7fe079b50ffa26aa53463b1cfe07 Mon Sep 17 00:00:00 2001 From: Ambrus Simon Date: Thu, 25 Jan 2018 19:17:27 +0100 Subject: [PATCH] Coverage save atexit trial --- api/web/start.py | 18 ++++++++---------- tests/bin/docker-tests.sh | 5 +++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/api/web/start.py b/api/web/start.py index cde4adc6d..1f0436e24 100644 --- a/api/web/start.py +++ b/api/web/start.py @@ -1,3 +1,4 @@ +import atexit import json import os import traceback @@ -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() diff --git a/tests/bin/docker-tests.sh b/tests/bin/docker-tests.sh index 0ea8412fa..a92114efb 100755 --- a/tests/bin/docker-tests.sh +++ b/tests/bin/docker-tests.sh @@ -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 \