def METHOD_NAME(self, result):
    if self.result is not None:
        raise ArgumentError("test result already set")
    if not isinstance(result, Result):
        raise ArgumentError("unexpected result type")
    self.result = result
    # Apply the XFAIL handling to resolve the result exit code.
    if self.isExpectedToFail():
        if self.result.code == PASS:
            self.result.code = XPASS
        elif self.result.code == FAIL:
            self.result.code = XFAIL