I wanted to share some work that has been done recently
blender-addon-tester is a python module that you install to your system that allows you to write and execute tests for an addon using pytest.
It came about when there were a lot of addons just broke on the move between 2.79 to 2.80. Everyone seems to have their own flow for keeping a addon up to date and some addons just got too stale to maintain. The importer for LWO models, for example, was removed from the blender-addon repo rather than maintain, which just so happened to be the one I was interested in. I asked around if there were any regressable tests for that existing addon, I got no reply, so I decided to do it myself the way I might expect a current software development team might.
So as a result the goal of the work and the eventual module was:
- Test a named addon (i.e. io_scene_obj, io_import_scene_lwo)
- write tests in pytest
- ability to run against multiple versions of blender, starting from 2.78, this allows testing to check if an addon can be maintained in a backwards compatiable way, that might not be preferred by the BF, but some addon developers may need to support some addons, bug fixs, on legacy versions.
- ability to run on multiple OSs
- written as much in python as possible, to reduce language thrashing
- addon checked into revision control, in this case git/github, this allows independent verification and forking, if required
- work with a continuous integration tool, e.g. Travis CI, Github Actions
- provide code coverage on coverage of tests against the addon code.
blender-addon-tester currently does all those things.
I recognise that there is regression testing in the blender flow. However this one is designed for ease of use. Once the module is installed into your system python, it downloads the version of blender you want to test against and maintains a version of that. From then on you edit the addon or the tests, in python, that’s it. It works on any system. Getting the likes of cmake working, particularly on windows is a pain, not impossible, but anything to get an addon developer to write tests is a plus.
This is a basic addon that shows integration:
This is the upgraded lwo importer, runs against blender 2.78 through 2.83 (the nightly at the time of writing)
An this is another basic addon integration, however the addon is the importer for OBJ from the blender-addon.git repo, which has been added as a submodule to this repo. This allows some one to write tests against an addon which is in a repo they don’t have write access to.
The tester is also being used over on the gmic addon for blender. @myselfhimself has been working on bringing part of the module up to snuff so that it is in a state that it could be checked into pypi.
pip install blender-addon-tester