Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Created October 1, 2016 22:45
Show Gist options
  • Save markrwilliams/22e2c1b39079a2b631db868472a242f1 to your computer and use it in GitHub Desktop.
Save markrwilliams/22e2c1b39079a2b631db868472a242f1 to your computer and use it in GitHub Desktop.
import pytest
from twisted.internet import defer
def successResultOf(d):
completed = []
d.addCallback(completed.append)
assert completed, "{!r} not yet fired".format(d)
return completed[0]
def test_successResultOf():
value = "OK"
assert successResultOf(defer.succeed(value)) == value
with pytest.raises(AssertionError) as exc:
successResultOf(defer.fail(ValueError()))
assert "Deferred" in str(exc.value)
with pytest.raises(AssertionError):
successResultOf(defer.Deferred())
assert "Deferred" in str(exc.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment