tests: Make import error tracebacks terse.

This will also disable exception chaining; we do not need it here.
This commit is contained in:
Umair Khan 2018-01-19 10:00:13 +05:00 committed by showell
parent 9565a5375f
commit 8f316183e0
1 changed files with 5 additions and 8 deletions

View File

@ -1,6 +1,5 @@
from functools import partial from functools import partial
import importlib
import random import random
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, \ 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: def check_import_error(test_name: Text) -> None:
try: try:
importlib.import_module(test_name) # Directly using __import__ is not recommeded, but here it gives
except ImportError: # clearer traceback as compared to importlib.import_module.
print() __import__(test_name)
print("Actual test to be run is %s, but import failed." % (test_name,)) except ImportError as exc:
print("Importing test module directly to generate clearer traceback:") raise exc from exc # Disable exception chaining in Python 3.
print()
raise
class Runner(DiscoverRunner): class Runner(DiscoverRunner):
test_suite = TestSuite test_suite = TestSuite