diff --git a/Jenkinsfile b/Jenkinsfile index c6b9a8c..16dddc6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,10 +3,18 @@ pipeline { agent any options { disableConcurrentBuilds() } + environment { + TMPDIR = "/tmp/$BUILD_TAG" + } stages { stage('Unit Tests') { steps { - sh 'tox -rv' + sh "mkdir ${env.TMPDIR}" + sh """ +virtualenv -p python3 ${env.TMPDIR}/venv/ +. ${env.TMPDIR}/venv/bin/activate +${env.TMPDIR}/venv/bin/pip install tox +PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -rv""" } post { always { @@ -39,6 +47,7 @@ pipeline { } } success { + sh "rm -rf ${env.TMPDIR}" cleanWs() } } diff --git a/tests/settings.py b/tests/settings.py index 855831b..2a167b4 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -9,3 +9,8 @@ DATABASES = { }, } } + +if 'postgres' in DATABASES['default']['ENGINE']: + for key in ('PGPORT', 'PGHOST', 'PGUSER', 'PGPASSWORD'): + if key in os.environ: + DATABASES['default'][key[2:]] = os.environ[key] diff --git a/tox.ini b/tox.ini index 1566ee8..d2da311 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,15 @@ setenv = DJANGO_SETTINGS_MODULE=authentic2.settings sqlite: DB_ENGINE=sqlite3 pg: DB_ENGINE=postgresql_psycopg2 + + JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml} coverage: COVERAGE=--cov=src --cov-branch --cov-append --cov-report xml --cov-report html + + # support for pg_virtualenv + PGPORT={env:PGPORT:} + PGHOST={env:PGHOST:} + PGUSER={env:PGUSER:} + PGPASSWORD={env:PGPASSWORD:} usedevelop = coverage: true deps = @@ -36,7 +44,7 @@ deps = oldldap: python-ldap<3 commands = ./getlasso.sh - py.test {env:COVERAGE:} -o junit_suite_name={envname} --junit-xml=junit-{envname}.xml {posargs:tests} + py.test {env:COVERAGE:} {env:JUNIT:} {posargs:tests} [testenv:pylint] basepython = python2.7