From ca95f8e4359325567fa441eef8f18cb710850eeb Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Sat, 25 Jan 2014 22:50:40 -0700 Subject: Moved sys.path-extending decorator to django.test.utils and used throughout test suite. Thanks Aymeric for the suggestion. --- django/test/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'django') diff --git a/django/test/utils.py b/django/test/utils.py index d205f5c9fb..7f47d29844 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -526,3 +526,15 @@ class TransRealMixin(object): requires_tz_support = skipUnless(TZ_SUPPORT, "This test relies on the ability to run a program in an arbitrary " "time zone, but your operating system isn't able to do that.") + + + +@contextmanager +def extend_sys_path(*paths): + """Context manager to temporarily add paths to sys.path.""" + _orig_sys_path = sys.path[:] + sys.path.extend(paths) + try: + yield + finally: + sys.path = _orig_sys_path -- cgit v1.3