Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored test case plugin loading and unloading. #204

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,14 @@ class TestDataProducerExample(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
_file = __file__

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def createScene(self):
self._locator = cmds.createNode('MhFlowViewportAPILocator')
cmds.setAttr(self._locator + '.numCubesX', 3)
cmds.setAttr(self._locator + '.numCubesY', 3)
cmds.setAttr(self._locator + '.numCubesZ', 3)

@classmethod
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the duplication, brought back to the base class.

def setUpClass(cls):
super(TestDataProducerExample, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestDataProducerExample, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)

def setUp(self):
super(TestDataProducerExample, self).setUp()
self.createScene()
Expand Down
20 changes: 1 addition & 19 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ class TestIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestIsolateSelect, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestIsolateSelect, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,7 @@ class TestIsolateSelectMayaSelectionHighlighting(mtohUtils.MayaHydraBaseTestCase

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestIsolateSelectMayaSelectionHighlighting, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestIsolateSelectMayaSelectionHighlighting, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests']

def setupScene(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,7 @@ class TestIsolateSelectSwitchToVP2(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestIsolateSelectSwitchToVP2, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestIsolateSelectSwitchToVP2, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests']

def setupScene(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ class TestUsdNativeInstancingIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestUsdNativeInstancingIsolateSelect, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestUsdNativeInstancingIsolateSelect, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,7 @@ class TestUsdPointInstancingIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestUsdPointInstancingIsolateSelect, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestUsdPointInstancingIsolateSelect, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,7 @@ class TestUsdPointInstancingIsolateSelectBBox(mtohUtils.MayaHydraBaseTestCase):

# Base class setUp() defines HdStorm as the renderer.

_pluginsToLoad = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']
_pluginsToUnload = []

@classmethod
def setUpClass(cls):
super(TestUsdPointInstancingIsolateSelectBBox, cls).setUpClass()
for p in cls._pluginsToLoad:
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

@classmethod
def tearDownClass(cls):
super(TestUsdPointInstancingIsolateSelectBBox, cls).tearDownClass()
# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p != 'mayaHydraFlowViewportAPILocator':
cmds.unloadPlugin(p)
_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

def setupScene(self):
self.proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
Expand Down
18 changes: 16 additions & 2 deletions test/testUtils/mtohUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class MayaHydraBaseTestCase(unittest.TestCase, ImageDiffingTestCase):
# Variables to be set in subclasses
_file = None
_requiredPlugins = []
_pluginsToUnload = []

# Unloading mayaHydraFlowViewportAPILocator crashes Maya (HYDRA-1304).
# Unloading mtoa succeeds on Linux, but fails on Windows and macOS
# with "cannot be unloaded because it is still in use" error.
_pluginsCantUnload = ['mayaHydraFlowViewportAPILocator', 'mtoa']

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -79,11 +85,13 @@ def setUpClass(cls):
if MAYAUSD_PLUGIN_NAME not in cls._requiredPlugins:
cls._requiredPlugins.append(MAYAUSD_PLUGIN_NAME)

for pluginToLoad in cls._requiredPlugins:
for p in cls._requiredPlugins:
# If a plugin fails to load, the entire test suite will be immediately aborted.
# Note that in the case of mtoa, the plugin might load successfully but not
# initialize properly, which means issues will only be caught in the actual tests.
cmds.loadPlugin(pluginToLoad)
if not cmds.pluginInfo(p, q=True, loaded=True):
cls._pluginsToUnload.append(p)
cmds.loadPlugin(p, quiet=True)

def setUp(self):
# Maya is not closed/reset between each test of a test suite,
Expand All @@ -94,6 +102,12 @@ def setUp(self):

@classmethod
def tearDownClass(cls):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base class now unloads plugins that were loaded specifically for the test.

# Clean out the scene to allow all plugins to unload cleanly.
cmds.file(new=True, force=True)
for p in reversed(cls._pluginsToUnload):
if p not in cls._pluginsCantUnload:
cmds.unloadPlugin(p)

if platform.system() == "Windows":
# On Windows, ADPClientService can linger around after a test ends and Maya closes,
# keeping a handle open into the temporary test directory that holds preferences,
Expand Down