diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2012-09-19 11:41:57 +0200 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2012-10-25 16:43:47 +0200 |
commit | 6bcc99e3767b87ee147a6233ca71b3f5ef2b9638 (patch) | |
tree | d61b7908b4d96b9af3f64c80d9697da7934b6236 /test | |
parent | a18097e23c3a97bb57c7f47c3edc9ce153364a83 (diff) |
D-Bus testing: better way of accessing function properties
Looking up the method via eval() no longer worked when test-dbus.py
was used as submodule. Better look up the function in the current
instance of the class via the method name, which itself can be
extracted from the current test id.
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-dbus.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/test/test-dbus.py b/test/test-dbus.py index d895a4c8..3ddeb7f4 100755 --- a/test/test-dbus.py +++ b/test/test-dbus.py @@ -34,6 +34,7 @@ import difflib import traceback import ConfigParser import io +import inspect import dbus from dbus.mainloop.glib import DBusGMainLoop @@ -412,11 +413,13 @@ class DBusUtil(Timeout): def getTestProperty(self, key, default): """retrieve values set with @property()""" - test = eval(self.id().replace("__main__.", "")) - if "properties" in dir(test): - return test.properties.get(key, default) - else: - return default + # Assume that IDs are composed of class name + dot + function name. + # Directly acccessing self._testMethodName would bypass the public + # Unittest API. + testMethodName = self.id().split('.')[-1] + testMethod = getattr(self, testMethodName) + properties = getattr(testMethod, "properties", {}) + return properties.get(key, default) def runTest(self, result, own_xdg=True, serverArgs=[], own_home=False, defTimeout=20): """Starts the D-Bus server and dbus-monitor before the test |