From adae3f2d715efef16dad336b3d57483000dd43da Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 19 Oct 2021 16:57:15 +0200
Subject: [PATCH] Hotpatch for logger - use DeviceContext to spawn a test
 device

---
 devices/test/common/test_lofar_logging.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/devices/test/common/test_lofar_logging.py b/devices/test/common/test_lofar_logging.py
index 98222563f..c1030b28f 100644
--- a/devices/test/common/test_lofar_logging.py
+++ b/devices/test/common/test_lofar_logging.py
@@ -14,6 +14,7 @@ from common import lofar_logging
 import logging
 from tango.server import Device
 from tango import device_server
+from tango.test_context import DeviceTestContext
 
 from test import base
 
@@ -82,11 +83,15 @@ class TestLofarLogging(base.TestCase):
                 logger.info("test")
 
         with mock.patch.object(device_server.DeviceImpl, '__info_stream') as m_info_stream:
-            # logs in the constructor already
-            mydevice = MyDevice(None, "MyDeviceName")
+            with DeviceTestContext(MyDevice) as mydevice:
+                self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device")
 
-            self.assertEqual(mydevice, self.memory_handler.records[0].tango_device, msg="configure_logging did not detect active Tango device")
-            self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device")
+                # Lookup our "test" logline among f.e. the debug messages output by Tango
+                test_record = [record for record in self.memory_handler.records if record.msg == "test"]
+
+                # Tango uses slightly different class representations of MyDevice, so
+                # we can't compare them direclty. Just verify we're talking about the same thing.
+                self.assertEqual(str(mydevice), str(test_record[0].tango_device), msg="configure_logging did not detect active Tango device")
 
 
     def test_log_exceptions(self):
-- 
GitLab