CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
793 stars 75 forks source link

Can't run specific tests targeting Blender #170

Closed Cobertos closed 6 years ago

Cobertos commented 6 years ago

I'm trying to run suite of tests that target Blender and I get the following error.

image

C:\Users\XXXXXX\Dropbox\Dev\RLD_Toolkit>C:\python35\python -m green tests.test_utils
AL lib: (EE) UpdateDeviceParams: Failed to set 44100hz, got 48000hz instead
E

Error in .tests.test_utils
TypeError: Test loader returned an un-runnable object.  Is "tests.test_utils" importable from your current location?  Maybe you forgot an __init__.py in your directory?  Unrunnable object looks like: None of type <class 'NoneType'> with dir ['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Ran 1 test in 0.987s

FAILED (errors=1)
Error: Not freed memory blocks: 8, total unfreed memory 0.008392 MB

I have also included my file heirarchy:

image

To give a bit of background on how Blender in Python works, Blender is compiled into a bpy.pyd file imported through import bpy whereby a headless Blender process will be spun up and the root python object is accessible in the current python environment. I see that this might be problematic according to https://github.com/CleanCut/green/issues/163.

Upon creating a minimal test case, the failure does indeed hinge on import bpy. Removing it will cause the tests that don't rely on Blender (only a select few) to be found and run properly.

I'm only posting this because while it doesn't work in green, I just tried and it does work in pytest (see below). From my experience with Blender as a Python module, I assume that Blender does some really weird import machinery rewriting to handle all its internal stuff but ultimately I'm not sure why pytest works and green does not.

If there is more troubleshooting information I can provide, let me know. I wasn't really sure where to go from here.

Pytest:

image

CleanCut commented 6 years ago

Where is the bpy.pyd file actually located on disk?

Cobertos commented 6 years ago

It's a very weird module in that bpy.pyd lives in C:\python35\Lib\site-packages and then loads all of it's supporting non-compiled Python resources from C:\python35\2.78 where 2.78 is the Blender version. For more insight, the final step of the build process looks something like:

copy bin\bpy.pyd C:\Python35\Lib\site-packages\  
copy bin\*.dll C:\Python35\Lib\site-packages\  
del C:\Python35\Lib\site-packages\python35.dll  
xcopy /E bin\2.78 C:\Python35\2.78\  

Calling import bpy in an interactive python session will load the module bpy fine and also allow for other Blender modules to load like mathutils. If you try import mathutils before import bpy it won't work.

CleanCut commented 6 years ago

You ran pytest on the whole project, but green on just one test file. Might as well try python -m green and see if that behaves any differently.

Other than that, I'm stumped. I don't use Blender or Windows, and without being able to poke around I'm not sure there's anything else I can do.

Any Windows experts out there want to give this one a shot?

CleanCut commented 6 years ago

Or blender experts?

Cobertos commented 6 years ago

It behaves the same and gives similar output for each file if I just run python -m green or green. I'll report back with any more information but I'm as stumped as you are.

In the meantime, it looks like if anything it's going to be something in bpy_interface.c or bpy_internal_import.c (the second one monkey-patches Python's import function apparently) and is then probably a Blender problem but I'll let you know

CleanCut commented 6 years ago

You're probably right, so I'm going to go ahead and close this issue. But if you find some new information that would point to a way that we could fix it in green, feel free to reopen.