From 715e6e8c8c655353f73aabd958db9053c402b042 Mon Sep 17 00:00:00 2001 From: Matt Johnson Date: Fri, 5 Mar 2021 10:51:17 -0800 Subject: [PATCH] move import of ufeSelectCmd inside selectPath() function in ufeUtils Attempting to import ufeSelectCmd before maya.standalone.initialize() has been called will raise an ImportError and cause tests to fail. For example, this would be the case for test cases that are decorated with the unittest.skipUnless() decorator and use ufeUtils.ufeFeatureSetVersion(), since the decorator will be executed before setUpClass has a chance to run and initialize maya.standalone. This change addresses that by pushing the import of ufeSelectCmd into the selectPath() function where it is used rather than having it at the top of the file. This ensures that the ufeUtils module can be imported and ufeUtils.ufeFeatureSetVersion() can be called safely before maya.standalone.initialize(). --- test/testUtils/ufeUtils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/testUtils/ufeUtils.py b/test/testUtils/ufeUtils.py index 8d6044bdd3..8d1e80cfeb 100644 --- a/test/testUtils/ufeUtils.py +++ b/test/testUtils/ufeUtils.py @@ -21,11 +21,7 @@ """ import ufe -try: - from maya.internal.ufeSupport import ufeSelectCmd -except ImportError: - # Maya 2019 and 2020 don't have ufeSupport plugin, so use fallback. - from ufeScripts import ufeSelectCmd + def getUfeGlobalSelectionList(): """ @@ -46,6 +42,15 @@ def selectPath(path, replace=False): replace (bool=False): Replace the selection with given UFE path """ + # Do this import inside this function rather than at the top of the file + # so that the module can be imported and ufeFeatureSetVersion() can be + # called prior to maya.standalone.initialize(). + try: + from maya.internal.ufeSupport import ufeSelectCmd + except ImportError: + # Maya 2019 and 2020 don't have ufeSupport plugin, so use fallback. + from ufeScripts import ufeSelectCmd + sceneItem = ufe.Hierarchy.createItem(path) if replace: selection = ufe.Selection()