Repository: Qiskit/qiskit

Issue:
Branch `master` is failing
<!-- commit 9134634f43bc858a32b4d6a9c3edf352e2f58873@master -->
Trying to build `master` at commit 9134634f43bc858a32b4d6a9c3edf352e2f58873 failed.
More info at: https://travis-ci.com/Qiskit/qiskit-terra/jobs/253757284


Discussion:
Not sure of the cause, but `from qiskit.providers.ibmq import IBMQ, IBMQBackend` in `qiskit.tools.monitor.backend_overview` is raising following #3325
I'm able to reproduce this locally, in the test when I give it credentials. I think it might be caused by the import changes made in #3325 https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/tools/__init__.py#L61 so that the `__init__` of `qiskit.tools` had things defined to autosummary. It might be causing weird import race condition because of namespace packaging. The IBMQ imports in the backend overview aren't fatal if they're missing: https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/tools/monitor/backend_overview.py#L24 moving the import as done in #3325 is probably causing backend_overview to get imported before python uses pkgutil to resolve the namespace packages for qiskit.providers with pkgutil. So if ibmq hasn't been added to the namespace yet this just catches the import error and passes and those module level imports are never defined.

I'm thinking a way to workaround this is to make the import a runtime import (although I'm generally not a fan of that, but it's probably a necessity here unlike the pylint circular import checker) so that we try the import only after all the imports are complete which should give us enough time to resolve the namespace packaging and add ibmq if it's present.
<!-- commit 9d2517403a4dda415759c9b154030801874d88c8@master -->
Trying to build `master` at commit 9d2517403a4dda415759c9b154030801874d88c8 failed.
More info at: https://travis-ci.com/Qiskit/qiskit-terra/jobs/254088565

Resolving patch:
diff --git a/qiskit/tools/monitor/backend_overview.py b/qiskit/tools/monitor/backend_overview.py
--- a/qiskit/tools/monitor/backend_overview.py
+++ b/qiskit/tools/monitor/backend_overview.py
@@ -19,12 +19,6 @@
 import math
 from qiskit.exceptions import QiskitError
 
-try:
-    # pylint: disable=import-error,no-name-in-module
-    from qiskit.providers.ibmq import IBMQ, IBMQBackend
-except ImportError:
-    pass
-
 
 def get_unique_backends():
     """Gets the unique backends that are available.
@@ -34,7 +28,14 @@ def get_unique_backends():
 
     Raises:
         QiskitError: No backends available.
+        ImportError: If qiskit-ibmq-provider is not installed
     """
+    try:
+        from qiskit.providers.ibmq import IBMQ
+    except ImportError:
+        raise ImportError("The IBMQ provider is necessary for this function "
+                          " to work. Please ensure it's installed before "
+                          "using this function")
     backends = []
     for provider in IBMQ.providers():
         for backend in provider.backends():
@@ -57,7 +58,16 @@ def backend_monitor(backend):
         backend (IBMQBackend): Backend to monitor.
     Raises:
         QiskitError: Input is not a IBMQ backend.
+        ImportError: If qiskit-ibmq-provider is not installed
     """
+    try:
+        # pylint: disable=import-error,no-name-in-module
+        from qiskit.providers.ibmq import IBMQBackend
+    except ImportError:
+        raise ImportError("The IBMQ provider is necessary for this function "
+                          " to work. Please ensure it's installed before "
+                          "using this function")
+
     if not isinstance(backend, IBMQBackend):
         raise QiskitError('Input variable is not of type IBMQBackend.')
     config = backend.configuration().to_dict()


Test patch: