It's not in this snippet, but on line 42 I think we need to clear out the in memory modulestore with xmodule.modulestore.django.clear_existing_modulestores()