You should use `call_command` like in the code commented out above, similar to how you are invoking it here:

```
out = StringIO()
call_command('dumpdata', stdout=out)
```