Charles Flèche's blog

Testing USD hooks outside of Blender

Part of our pipeline is automated through a Blender extension that pre / post process USD with USDHooks. For a long time, our integration tests had to actually run the Blender executable: we had to import the USD modules, and those were not available through the pip installable bpy module. Installing usd-core alongside bpy wouldn't work: we would have two USD libraries running into the same process (one from usd-core, the other from bpy) and that's a recipe for disater.

Thankfully, since Blender 4.4, the function bpy.expose_bundled_modules() makes the third-party bundled modules, notably USD, available from the rest of the application.

import unittest

import bpy

bpy.expose_bundled_modules()

from pxr import Usd

class MyTest(unittest.TestCase):
    ...

Thanks to bpy.expose_bundled_modules() we can now run our tests fully from a Python interpreter, without running the Blender executable: - as we stay fully in the Python world, the setup is the same on local Windows workstation and Linux CI machines - we can simply run and debug our tests from the native IDEs integrations