From 7248a3366b2fe1e21aec8da3a11c9bcb7914c689 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Thu, 18 Jan 2018 10:43:29 +0500 Subject: [PATCH] tests: Change print_error_message to check_import_error. --- zerver/lib/test_runner.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/zerver/lib/test_runner.py b/zerver/lib/test_runner.py index 3b9c3d91b4..af829c5bf3 100644 --- a/zerver/lib/test_runner.py +++ b/zerver/lib/test_runner.py @@ -1,5 +1,6 @@ from functools import partial +import importlib import random from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, \ @@ -353,25 +354,15 @@ class ParallelTestSuite(django_runner.ParallelTestSuite): # definitions. self.subsuites = SubSuiteList(self.subsuites) # type: ignore # Type of self.subsuites changes. -def print_error_message(test_name: Text) -> None: - command = [sys.executable, "-c", "import %s" % test_name] - print() - print("Actual test to be run is %s, but import failed." % (test_name,)) - print("Importing test module directly to generate clearer traceback:") - print(" {command}".format(command=' '.join(command))) - print() +def check_import_error(test_name: Text) -> None: try: - subprocess.check_call(command) - except subprocess.CalledProcessError: + importlib.import_module(test_name) + except ImportError: print() - print("If that traceback is confusing, try doing the import " - "inside `./manage.py shell`.") - else: + print("Actual test to be run is %s, but import failed." % (test_name,)) + print("Importing test module directly to generate clearer traceback:") print() - print("Import unexpectedly succeeded! Something is wrong.") - print("Try running `import %s` inside `./manage.py shell`." % (test_name,)) - print("If that works, you may have introduced an import cycle.") - print() + raise class Runner(DiscoverRunner): test_suite = TestSuite