I have this file with unit tests:
#file tests.py
class TestResults(TestBase): ...
class TestRegisteredFunctions(TestBase):
"""Tests functions registered dynamically."""
def testNewFunction(self):
"""Server must register new functions."""
# Register new function
def square(num):
return num * num
self.server.register('square', square)
res = self.jsonrpc_req(1, 'square', [2])
self.assertEqual(res['result'], 4)
Most of the code is omitted because will not be relevant.
My problem is I need to grab that "square" function.
For example doing getattr(tests, 'square')
in another module would correctly get me that square function. How can I achieve such result?