Skip to content
Snippets Groups Projects
Commit 86250979 authored by Colton Leekley-Winslow's avatar Colton Leekley-Winslow Committed by GitHub
Browse files

Merge pull request #489 from scitran/integration-test-coverage

Record coverage for integration tests
parents 2b20c383 21dc91c4
No related branches found
No related tags found
No related merge requests found
import atexit
import json
import os
import sys
import traceback
......@@ -227,7 +229,8 @@ def app_factory(*_, **__):
application = webapp2.WSGIApplication(routes, debug=config.__config['core']['debug'])
application.router.set_dispatcher(dispatcher)
application.request_class = SciTranRequest
if os.environ.get("SCITRAN_RUNTIME_COVERAGE") == "true":
start_coverage()
# configure new relic
if config.__config['core']['newrelic']:
try:
......@@ -243,3 +246,16 @@ def app_factory(*_, **__):
sys.exit(1)
return application
# Functions to enable code coverage when API is started for testing
def start_coverage():
import coverage
config.log.info("Enabling code coverage")
cov = coverage.coverage(source=["api"], data_suffix="integration-tests")
cov.start()
atexit.register(save_coverage, cov)
def save_coverage(cov):
config.log.info("Saving coverage")
cov.stop()
cov.save()
# vim: filetype=python
import sys
import os.path
from api import api
application = api.app_factory()
......@@ -76,6 +76,7 @@ SCITRAN_RUNTIME_PORT=${SCITRAN_RUNTIME_PORT:-"8080"}
SCITRAN_RUNTIME_UWSGI_INI=${SCITRAN_RUNTIME_UWSGI_INI:-""}
SCITRAN_RUNTIME_BOOTSTRAP=${SCITRAN_RUNTIME_BOOTSTRAP:-"./bootstrap.json"}
SCITRAN_RUNTIME_SSL_PEM=${SCITRAN_RUNTIME_SSL_PEM:-""}
SCITRAN_RUNTIME_COVERAGE=${SCITRAN_RUNTIME_COVERAGE:-"false"}
SCITRAN_CORE_DRONE_SECRET=${SCITRAN_CORE_DRONE_SECRET:-$( openssl rand -base64 32 )}
......@@ -106,7 +107,7 @@ clean_up () {
kill $MONGOD_PID || true
kill $UWSGI_PID || true
deactivate || true
wait
wait 2> /dev/null
}
trap clean_up EXIT
......
......@@ -4,6 +4,8 @@ set -eu
unset CDPATH
cd "$( dirname "${BASH_SOURCE[0]}" )/../.."
rm -f .coverage.integration-tests
USAGE="
Usage:\n
$0 <api-base-url> <mongodb-uri>\n
......@@ -40,7 +42,7 @@ rm -rf test/integration_tests/python/__pycache__
BASE_URL="$SCITRAN_SITE_API_URL" \
MONGO_PATH="$MONGODB_URI" \
py.test --cov=api --cov-append test/integration_tests/python
py.test test/integration_tests/python
newman run test/integration_tests/postman/integration_tests.postman_collection -e test/integration_tests/postman/environments/integration_tests.postman_environment
......
......@@ -13,7 +13,13 @@ SCITRAN_PERSISTENT_PATH="$( mktemp -d )"
clean_up () {
kill $API_PID || true
wait 2> /dev/null
rm -rf "$SCITRAN_PERSISTENT_PATH"
# Report on unit tests and integration tests separately
coverage report -m
rm .coverage
coverage combine
coverage report -m
}
trap clean_up EXIT
......@@ -29,6 +35,7 @@ trap clean_up EXIT
SCITRAN_RUNTIME_PORT=8081 \
SCITRAN_CORE_DRONE_SECRET=integration-tests \
SCITRAN_RUNTIME_COVERAGE="true" \
./bin/run-dev-osx.sh -T -U -I &
API_PID=$!
......
......@@ -8,6 +8,19 @@ cd "$( dirname "${BASH_SOURCE[0]}" )/../.."
./test/bin/run-unit-tests.sh
clean_up () {
kill $API_PID || true
wait 2> /dev/null
# Report on unit tests and integration tests separately
# Only submit integration test coverage to coveralls
coverage report -m
rm .coverage
coverage combine
coverage report -m
}
trap clean_up EXIT
API_BASE_URL="http://localhost:8081/api"
SCITRAN_PERSISTENT_DB_PORT=${SCITRAN_PERSISTENT_DB_PORT:-"9001"}
SCITRAN_PERSISTENT_DB_URI=${SCITRAN_PERSISTENT_DB_URI:-"mongodb://localhost:$SCITRAN_PERSISTENT_DB_PORT/scitran"}
......@@ -23,7 +36,9 @@ uwsgi --http "localhost:8081" --master --http-keepalive \
--logformat '%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)" request_id=%(request_id)' \
--env "SCITRAN_PERSISTENT_DB_URI=$SCITRAN_PERSISTENT_DB_URI" \
--env "SCITRAN_PERSISTENT_PATH=$SCITRAN_PERSISTENT_PATH" \
--env "SCITRAN_PERSISTENT_DATA_PATH=$SCITRAN_PERSISTENT_DATA_PATH" &
--env "SCITRAN_PERSISTENT_DATA_PATH=$SCITRAN_PERSISTENT_DATA_PATH" \
--env 'SCITRAN_RUNTIME_COVERAGE=true' &
API_PID=$!
./test/bin/run-integration-tests.sh \
"$API_BASE_URL" \
......
......@@ -16,4 +16,6 @@ echo "Checking for files with windows style newline:"
# Which have a mismatched __file__ attribute when loaded in docker container
rm -rf test/unit_tests/python/__pycache__
PYTHONPATH="$( pwd )" py.test --cov=api --cov-append test/unit_tests/python
rm -f .coverage
PYTHONPATH="$( pwd )" py.test --cov=api test/unit_tests/python
coverage==4.0.3
coveralls==1.1
pylint==1.5.3
pymongo==3.2
pytest-cov==2.2.0
pytest-watch==3.8.0
pytest==2.8.5
python-dateutil==1.5
requests==2.9.1
mock==2.0.0
testfixtures==4.10.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment