Test framework: fix import logic for sphynx.
[vpp.git] / test / vpp_papi_provider.py
index 6cbde71..8153e03 100644 (file)
@@ -6,22 +6,19 @@ from collections import deque
 from six import moves
 
 from hook import Hook
+from vpp_l2 import L2_PORT_TYPE
 
 # Sphinx creates auto-generated documentation by importing the python source
 # files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
 # the vpp_papi_provider.py file to be importable without having to build
 # the whole vpp api if the user only wishes to generate the test documentation.
-do_import = True
-try:
-    no_vpp_papi = os.getenv("NO_VPP_PAPI")
-    if no_vpp_papi == "1":
-        do_import = False
-except:
-    pass
 
-if do_import:
+try:
     from vpp_papi import VPP
-    from vpp_l2 import L2_PORT_TYPE
+except ImportError:
+    if not os.getenv("NO_VPP_PAPI") == 1:
+        raise
+    pass
 
 # from vnet/vnet/mpls/mpls_types.h
 MPLS_IETF_MAX_LABEL = 0xfffff