diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2016-06-26 16:24:25 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2016-06-26 16:24:25 -0400 |
| commit | f1afa52fca454a61784e4c95eace75cd50eb6d09 (patch) | |
| tree | fb77d287f7b648644ade4b9467c8fd2df928a130 /passlib | |
| parent | 682413729505e2427e46db84710fef3367e5d770 (diff) | |
| download | passlib-f1afa52fca454a61784e4c95eace75cd50eb6d09.tar.gz | |
bugfix: test_ext_django: try to give better error message when
django's tests fail to import, don't let it get swallowed by python's importer.
Diffstat (limited to 'passlib')
| -rw-r--r-- | passlib/tests/test_ext_django.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/passlib/tests/test_ext_django.py b/passlib/tests/test_ext_django.py index a931415..4f78840 100644 --- a/passlib/tests/test_ext_django.py +++ b/passlib/tests/test_ext_django.py @@ -14,7 +14,7 @@ import sys from passlib.apps import django10_context, django14_context, django16_context from passlib.context import CryptContext import passlib.exc as exc -from passlib.utils.compat import iteritems, unicode, get_method_function, u, PY3 +from passlib.utils.compat import iteritems, unicode, get_method_function, u, PY3, suppress_cause from passlib.utils import memoized_property # tests from passlib.tests.utils import TestCase, skipUnless, TEST_MODE, has_active_backend, handler_derived_from @@ -846,12 +846,24 @@ elif has_min_django: log.info("using django tests from source path: %r", source_path) tests_path = os.path.join(source_path, "tests") sys.path.insert(0, tests_path) - from auth_tests import test_hashers as test_hashers_mod - sys.path.remove(tests_path) + try: + from auth_tests import test_hashers as test_hashers_mod + except ImportError as err: + raise suppress_cause( + EnvironmentError("error trying to import django tests " + "from source path (%r): %r" % + (source_path, err))) + finally: + sys.path.remove(tests_path) else: hashers_skip_msg = "requires PASSLIB_TESTS_DJANGO_SOURCE_PATH to be set" + if TEST_MODE("full"): + # print warning so user knows what's happening + sys.stderr.write("\nWARNING: $PASSLIB_TESTS_DJANGO_SOURCE_PATH is not set; " + "can't run Django's own unittests against passlib.ext.django\n") + elif DJANGO_VERSION: hashers_skip_msg = "django version too old" |
