Skip to content

Instantly share code, notes, and snippets.

@specialunderwear
Created May 13, 2019 14:57
Show Gist options
  • Save specialunderwear/5c0998a801a3c709c600fa97edf4b2f3 to your computer and use it in GitHub Desktop.
Save specialunderwear/5c0998a801a3c709c600fa97edf4b2f3 to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
from unittest.mock import patch
@contextmanager
def fake_autocreated(many_to_many_manager):
"Do not give a shit about any intermediate models, just update the relation"
with patch.object(many_to_many_manager.through._meta, "auto_created", True):
yield many_to_many_manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment