from django.core import urlresolvers from django.utils import timesince # set up a class to turn off reverse via monkeypatch...we do not care about its details class PatchReverse: def __enter__(self): self.old_method = urlresolvers.reverse urlresolvers.reverse = lambda view_name, args, kwargs, current_app: 'stub' def __exit__(self, type, value, traceback): urlresolvers.reverse = self.old_method # nor do we care about the details of timesince...note that we monkeypatch the one # from django.utils...it is harder to monkeypatch template filters due to django # registration mechanisms class PatchTimeSince: def __enter__(self): self.old_method = timesince.timesince timesince.timesince = lambda arg: 'stub' def __exit__(self, type, value, traceback): timesince.timesince = self.old_method with PatchReverse(): with PatchTimeSince(): from django.template.loader import render_to_string render_to_string('activity.html', dict(...))