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

tests have s subtle execution order bug #103

Open
theodox opened this issue Jul 10, 2018 · 10 comments
Open

tests have s subtle execution order bug #103

theodox opened this issue Jul 10, 2018 · 10 comments
Labels

Comments

@theodox
Copy link
Owner

theodox commented Jul 10, 2018

Looking at the tests in my most recent pytcharm install, it appears that the monkeypatching in test_Nested is failing. It used to work, but now when I run the tests I can see that before the patch is applied most of mGui is already loaded. So, replacing cmds.whatever in this test has no effect because the loaded modules already have a reference to the proper maya cmds version -- at least, that's what I think is happening.

@theodox theodox added the bug label Jul 10, 2018
@bob-white
Copy link
Collaborator

That is super weird.
Just did a quick local run and the whole test suite passed. Though I'm just running them manually from sublime, not from pycharm.

I wonder if its some oddity with the pycharm test runner, any idea how well it isolates tests between runs? Because if it just runs them all alphabetically I can see how running test_api first would mess up the mocking in test_nested

@theodox
Copy link
Owner Author

theodox commented Jul 11, 2018 via email

bob-white added a commit that referenced this issue Jul 12, 2018
Clears mGui from the currently imported modules. This allows for a
completely fresh version of the module to be imported.

Helps solve #103 which seems to be an issue where an earlier test has
already imported mGui before certain commands could be properly mocked.
@bob-white
Copy link
Collaborator

Realized I never hit comment before actually pushing a new branch.
But the basic idea in there is that we remove mGui from sys.modules before applying the mocks. That way when we re-import mGui, it will be relying on the altered namespace.

Not sure if its really the best fix, but I use this method when doing GUI tests in maya, as it provides a functional if hacky reload for the whole module.

@theodox
Copy link
Owner Author

theodox commented Jul 13, 2018

Does it fix the ‘you can’t reload metaclass hierarchies’ problem?

@bob-white
Copy link
Collaborator

Yeah, that's actually why I started using it for testing in Maya.
I couldn't ever get the proper module order for reload to not be awful.
So I just went with, kill it and start over.

There are some issues if you wipe out the module while a window is open, because it loses a bunch of the weakrefs, but better than restarting Maya.

@theodox
Copy link
Owner Author

theodox commented Jul 17, 2018

yeah, I think we can call reloading with open UI an 'advanced feature' we don't want to support.

@theodox
Copy link
Owner Author

theodox commented Jul 23, 2018

Thinking this over I'm wondering if the right thing to do is to a full-blown conversion to mocks. I did a kind of half-assed mock for some tests but its inconsistently applied, I think we could make the testing situation a lot clearer if we went ahead and did it everywhere

@bob-white
Copy link
Collaborator

Yeah you're probably right.
You want to just use mock? It would be the default if/when we can ever upgrade our Maya code to py3. Or do you think there is a benefit from us continuing to roll our own?

Depending how deep we need to go for this, it might be worth checking with some of the other Maya projects, someone might have a base we can build off of.

@theodox
Copy link
Owner Author

theodox commented Jul 24, 2018

This is from something else I'm playing with... but it works, and I think is showcases a way forward:

import sys
import mock
from types import ModuleType

_maya = ModuleType('maya')
_cmds = ModuleType('cmds')
_api = ModuleType('api')
_openMaya= ModuleType('OpenMaya')

class MVector(list):
    pass

class MMatrix(list):
    pass
_openMaya.MVector = MVector
_openMaya.MMatrix = MMatrix


_maya.cmds = mock.MagicMock()

sys.modules['maya'] = _maya
sys.modules['maya.cmds'] = _cmds
sys.modules['maya.api'] = _api
sys.modules['maya.api.OpenMaya'] = _openMaya

import maya.cmds as cmds

import sys
sys.path.append(r"D:\prj\ulMaya\mayaScene")
import proxy_replacement as pr

ls = cmds.ls
ls.side_effect = [('pCube1', 'transform')]
result =  pr.proxy('pCube1')
ls.side_effect = [('pCube1.translate', 'double3')]
ga = cmds.getAttr
ga.side_effect = [[(1,2,3)]]
print result.translate

@theodox
Copy link
Owner Author

theodox commented Jul 25, 2018

incidentally it looks like maya 2019 (the beta) is breaking all the forms classes -- seems to have trouble finding children of a formLayout :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants