Hi,
I’m working on the TangoBox-9.2 virtual machine and I upgraded PyTango to the latest version (9.2.6).
I need to test the code of my devices with nose using DeviceTestContext from the tango.test_context module.
Simplyfing my situation, I have two devices, number 1 and number 2; device 1 has a command “TurnOn” that sets both his and device 2 state on ON. The code is something like this:
class Dev1(Device):
dev2 = "sim/test/dev2"
def init_device(self):
self.set_state(PyTango.DevState.OFF)
@command
def TurnOn(self):
self.set_state(PyTango.DevState.ON)
proxy_dev2 = PyTango.DeviceProxy(self.dev2)
proxy_dev2.command_inout('TurnOn')
class Dev2(Device):
def init_device(self):
self.set_state(PyTango.DevState.OFF)
@command
def TurnOn(self):
self.set_state(PyTango.DevState.ON)
The test I wrote is this:
from Dev1 import Dev1
from Dev2 import Dev2
from tango.test_context import DeviceTestContext
import PyTango
def test_TurnOn():
dev2_context = DeviceTestContext(Dev2, host="localhost", process=True)
with dev2_context as dev2_test:
class Dev1Test(Dev1):
#overwrite dev2 to get access to the test device
dev2 = dev2_context.get_device_access()
dev1_context = DeviceTestContext(Dev1Test, host="localhost", process=True)
with dev1_context as dev1_test:
dev1_test.TurnOn()
assert dev1_test.State() == PyTango.DevState.ON
assert dev2_test.State() == PyTango.DevState.ON
If I run nose on this test everything works fine. But I’d like to set the DeviceProxy as global variable on device 1, like this:
class Dev1(Device):
dev2 = PyTango.DeviceProxy("sim/test/dev2")
def init_device(self):
self.set_state(PyTango.DevState.OFF)
@command
def TurnOn(self):
self.set_state(PyTango.DevState.ON)
self.dev2.command_inout('TurnOn')
so if I need to use the DeviceProxy in another command I didn’t have to create another one.
Well, in this case the same test (with the variable dev1 as a DeviceProxy in the Dev1Test class) doesn’t work anymore.
error reg.pngIt gives me this error if the device “sim/test/dev2” isn’t registered:
error start.pngAnd, if the device is registered, the DeviceTestContext doesn’t start:
The same thing happens using the older tango.test_context module from PyTango 9.2.1.
Is this a normal behaviour or some kind of bug? Am I missing something?
Sorry for the long post but I wanted to try to be as clear as possible.
Thanks to everyone who wants to help me.
Regards
Maurizio