Hey guys,
I stumbled across a bit of an issue when writing integration tests
using the unittest/unittest2 frameworks for my project that uses RPyC.
If you get an unexpected exception on the server side, rpyc usually
prints this out on the client side using sys.excepthook, however when
running in unittest all exceptions are caught and stored by the
framework, so sys.excepthook is never called. I solved this by
extending test result class in my unittest file (should work for both
unittest and unittest2):

class RPyCTestResult(unittest.TextTestResult):
    def _exc_info_to_string(self, err, test):
        s = super(RPyCTestResult, self)._exc_info_to_string(err, test)
        exctype, value, tb = err
        if hasattr(value, "_remote_tb"):
            s += "\n========= Remote traceback ========\n"
            s += "\n--------------------------------\n\n".join(value._remote_tb)
            s += "===== End of Remote traceback ======\n"
        return s

if __name__ == "__main__":
     
unittest.main(testRunner=unittest.TextTestRunner(resultclass=RPyCTestResult))

Obviously this will only work if you run the python file directly
(need to figure out how to integrate with nose). Cheers for writing a
great RPC library btw, using rpyc has been a pleasurable experience :)
Regards,
Oliver

Reply via email to