diff --git a/SAS/LSMR/test/t_lsmrapp_specification_functional.py b/SAS/LSMR/test/t_lsmrapp_specification_functional.py
index eae316ec7c8ddad09b3d6577c5640bc60f06cb97..36568de569f8d63d858878d489ffcdbca53ecfe8 100755
--- a/SAS/LSMR/test/t_lsmrapp_specification_functional.py
+++ b/SAS/LSMR/test/t_lsmrapp_specification_functional.py
@@ -28,27 +28,21 @@
 # todo: We should probably also fully test behavior wrt mandatory and nullable fields.
 
 
+import os
+import sys
 import unittest
 import requests
 import json
 from datetime import datetime
 from requests.auth import HTTPBasicAuth
 from lofar.common import dbcredentials
+import logging
 
-BASE_URL = 'http://localhost:8777'
+DJANGO_PORT=os.environ.get('DJANGO_TEST_PORT', 0)
+BASE_URL = 'http://localhost:%s' % (DJANGO_PORT,)
 
-
-# Read Login credentials  (todo: when we authorize functionality based on specific users, we need sth better than this)
-
-# this requires a config file .lofar/dbcredentials/lsmr.ini, with contents as such (adapt as needed):
-#
-# [database:lsmr_ldap]
-# user = ldapuser
-# password = ldappass
-#
 dbc = dbcredentials.DBCredentials()
 ldap_credentials = dbc.get("lsmr_ldap")
-print('Using ldap credentials', ldap_credentials.stringWithHiddenPassword())
 
 def _call_API_and_assert_expected_response(self, url, call, data, expected_code, expected_content):
     """
@@ -2080,5 +2074,7 @@ class WorkRequestRelationBlueprintTestCase(unittest.TestCase):
 
 
 if __name__ == "__main__":
+    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
+                        level=logging.INFO)
     unittest.main()
 
diff --git a/SAS/LSMR/test/t_lsmrapp_specification_functional.run b/SAS/LSMR/test/t_lsmrapp_specification_functional.run
index 406cb3e8d89d6c8b269877f9aebcf4c3158738ac..6722f7a83b80fb6f1811e9af7dc8b6fe0fd7a74c 100755
--- a/SAS/LSMR/test/t_lsmrapp_specification_functional.run
+++ b/SAS/LSMR/test/t_lsmrapp_specification_functional.run
@@ -1,24 +1,75 @@
-#!/bin/sh
+#!/bin/bash
+set +x
 
-echo "---"
-echo "! This requires a running Postgres instance with a configured database according to the settings.py configuration."
-echo "! You can run the lsmr_testdatabase command to fire up a temporary instance."
-echo "---"
+mkdir -p ~/.lofar/dbcredentials
+
+DJANGO_TEST_DATABASE_NAME="lsmr_test_`uuidgen | sed 's/-/_/g'`"
+CREDENTIALS_PATH="$HOME/.lofar/dbcredentials/$DJANGO_TEST_DATABASE_NAME.ini"
+
+echo "creating test credentials file: $CREDENTIALS_PATH"
+echo "[database:$DJANGO_TEST_DATABASE_NAME]
+host=localhost
+type=postgres
+database=$DJANGO_TEST_DATABASE_NAME
+port=7654
+user=lsrm
+password=lsrm
+" > "$CREDENTIALS_PATH"
+
+
+
+#keep track of helper application pids to kill in teardown
+PIDS=
+
+# setup propagation of signals to child processes
+teardown() {
+    echo "tearing down test environment"
+    for PID in $PIDS
+    do
+        # get the full command
+        CMD="`ps --pid $PID h -o command`"
+        echo "killing helper application: $CMD"
+
+        # and kill it
+        kill -TERM $PID
+    done
+
+    echo "removing test credentials file: $CREDENTIALS_PATH"
+    rm $CREDENTIALS_PATH
+}
+
+## Trap upon signals and upon normal exit.
+trap 'STATUS=$?; teardown; exit $STATUS' SIGHUP SIGINT SIGQUIT SIGKILL SIGTERM
+
+
+
+
+# fire up a postgres test database
+lsmr_testdatabase -C $DJANGO_TEST_DATABASE_NAME &
+PIDS="$! $PIDS"
+sleep 5
+echo "Started Django test database server\n\n"
 
 # Run Django test instance
-PORT=8777
-lsmr -p $PORT &
-DJANGO_PID=$!
-echo "Started Django server with PID: " $DJANGO_PID
-sleep 15
+DJANGO_TEST_PORT=8777
+lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME &
+PIDS="$! $PIDS"
+sleep 5
+echo "Started lsmr django server\n\n"
+
+export DJANGO_TEST_PORT=$DJANGO_TEST_PORT
+export LSMR_DBCREDENTIALS=$DJANGO_TEST_DATABASE_NAME
 
 # Run test
-./t_lsmrapp_specification_functional.py
-EXITCODE=$?
+./t_lsmrapp_specification_functional.py &
+TEST_PID=$!
+PIDS="$TEST_PID $PIDS"
+
+wait "$TEST_PID"
+# wait again (to get the status code of the test)
+wait "$TEST_PID"
+TEST_EXIT_CODE=$?
 
-# Kill Django test instance
-pkill -f "lofar/sas/lsmr/manage.py runserver 0.0.0.0:$PORT"
-kill $DJANGO_PID
+teardown
 
-# Return with success or failure of actual test
-exit $EXITCODE
+exit $TEST_EXIT_CODE