@contextmanager
def persistent_grades_feature_flags(global_flag, enabled_for_all_courses=False, course_id=None, enabled_for_course=False):
 PersistentGradesEnabledFlag.objects.create(enabled=global_flag, enabled_for_all_courses=enabled_for_all_courses)
 if course_id:
  CoursePersistentGradesFlag.objects.create(course_id=course_id, enabled=enabled_for_course)
 (yield)

@ contextmanager def persistent_grades_feature_flags ( global_flag , enabled_for_all_courses = False , course_id = None , enabled_for_course = False ) : PersistentGradesEnabledFlag . objects . create ( enabled = global_flag , enabled_for_all_courses = enabled_for_all_courses ) if course_id : CoursePersistentGradesFlag . objects . create ( course_id = course_id , enabled = enabled_for_course ) ( yield )
most test cases will use a single call to this manager .