Yelp/Testify — pull request #71 by sumeet (2012-04-23 03:47:08+00:00)
Title: Add let().

A decorator enabling lazily evaluated test helpers. This feature is extremely useful.

Before:
```python
class MyTest(TestCase):

@setup
def create_user(self):
self.user = create_user()

@setup
def create_business(self):
self.business = create_business()

def test_with_user(self):
assert self.user

def test_with_user_and_business(self):
assert self.user and self.business
```

There's waste in `test_with_user()` because it doesn't use `business`.

After:
```python
class MyTest(TestCase):

@let
def user(self):
return create_user()

business = let(lambda self: create_business())

def test_with_user(self):
assert self.user

def test_with_user_and_business(self):
assert self.user and self.business
```

I think the Rubyist in me mostly prefers the terser syntax with the lambda. Both make me very happy, though.

Stolen from [RSpec](https://www.relishapp.com/rspec/rspec-core/docs/helper-methods/let-and-let) (even [their tests](https://github.com/rspec/rspec-core/blob/master/spec/rspec/core/let_spec.rb)).