From f74e1b765b9bc70146db793d6762783e4f234ffe Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 28 Mar 2019 10:16:13 +0000
Subject: [PATCH] SW-382: fixed test_add_queue_raises. Fixed handling of QUEUE
 variable which enable usage from ctest (via the .run file) and running the
 test from within pycharm

---
 .../python/messaging/test/t_messagebus.py        | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/LCS/Messaging/python/messaging/test/t_messagebus.py b/LCS/Messaging/python/messaging/test/t_messagebus.py
index 596e885adbd..10e0a72f19c 100644
--- a/LCS/Messaging/python/messaging/test/t_messagebus.py
+++ b/LCS/Messaging/python/messaging/test/t_messagebus.py
@@ -35,7 +35,7 @@ from lofar.messaging.messagebus import *
 from lofar.messaging.exceptions import MessageBusError, InvalidMessage
 
 TIMEOUT = 1.0
-
+QUEUE = sys.argv[-1] if len(sys.argv) > 1 and "t_messagebus.py" not in sys.argv[-1] else "t_messagebus.queue"
 logger = logging.getLogger(__name__)
 
 
@@ -78,12 +78,11 @@ class FromBusNotInContext(unittest.TestCase):
         self.frombus = FromBus(QUEUE)
         self.error = re.escape("[FromBus] No active receiver") + '.*'
 
-    @unittest.skip("Why is this important? It's a private function anyway...")
     def test_add_queue_raises(self):
         """
         Adding a queue when outside context must raise MessageBusError
         """
-        with self.assertRaisesRegex(MessageBusError, self.error):
+        with self.assertRaises(MessageBusError):
             self.frombus._add_queue("fooqueue")
 
     def test_receive_raises(self):
@@ -296,7 +295,12 @@ class SendReceiveMessage(unittest.TestCase):
 
 
 if __name__ == '__main__':
-    logging.basicConfig(level=logging.INFO)
-    QUEUE = sys.argv[1] if len(sys.argv) > 1 else "testqueue"
-    del sys.argv[1:]
+    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG)
+
+    # delete last cmdlime argument if it holds the test-queue-name,
+    # so it is not passed on to the unittest framework.
+    # see also t_messagebus.run
+    if len(sys.argv) > 1 and sys.argv[-1].strip() != "t_messagebus.py":
+        del sys.argv[-1]
+
     unittest.main()
-- 
GitLab