Skip to content

Commit d5886b8

Browse files
authored
Merge pull request #1 from kaapstorm/readme_chaining
Add example of chaining fixtures
2 parents 29f81c5 + d8c7b0b commit d5886b8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,32 @@ def test_database():
186186
...
187187
```
188188

189+
### Chaining fixtures
190+
191+
Fixtures that use other fixtures should be decorated with `@use`, so
192+
that fixture dependencies are chained.
193+
194+
```python
195+
@use("db")
196+
def parent_fixture():
197+
daedalus = Person.objects.create(name='Daedalus')
198+
yield daedalus
199+
daedalus.delete()
200+
201+
@use(parent_fixture)
202+
@fixture
203+
def child_fixture():
204+
daedalus = parent_fixture()
205+
icarus = Person.objects.create(name='Icarus', father=daedalus)
206+
yield
207+
208+
@use(child_fixture)
209+
def test_flight():
210+
flyers = Person.objects.all()
211+
...
212+
```
213+
214+
189215
## Running the `unmagic` test suite
190216

191217
```sh

0 commit comments

Comments
 (0)