mirror of https://github.com/zulip/zulip.git
tests: Make import error tracebacks terse.
This will also disable exception chaining; we do not need it here.
This commit is contained in:
parent
9565a5375f
commit
8f316183e0
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue