From 8f316183e09654cd0d34e396f2931c99b3832626 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Fri, 19 Jan 2018 10:00:13 +0500 Subject: [PATCH] tests: Make import error tracebacks terse. This will also disable exception chaining; we do not need it here. --- zerver/lib/test_runner.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/zerver/lib/test_runner.py b/zerver/lib/test_runner.py index cb2fd99b73..78262c196c 100644 --- a/zerver/lib/test_runner.py +++ b/zerver/lib/test_runner.py @@ -1,6 +1,5 @@ from functools import partial -import importlib import random from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, \ @@ -356,13 +355,11 @@ class ParallelTestSuite(django_runner.ParallelTestSuite): def check_import_error(test_name: Text) -> None: try: - importlib.import_module(test_name) - except ImportError: - print() - print("Actual test to be run is %s, but import failed." % (test_name,)) - print("Importing test module directly to generate clearer traceback:") - print() - raise + # Directly using __import__ is not recommeded, but here it gives + # clearer traceback as compared to importlib.import_module. + __import__(test_name) + except ImportError as exc: + raise exc from exc # Disable exception chaining in Python 3. class Runner(DiscoverRunner): test_suite = TestSuite