Home

Awesome

Github Actions pypi.org nightly tests Github Actions local Python wheel tests codecov

blender-addon-tester

Background

Blender can be extended with python addons.

When an addonsreleased, it's developped to work with the current version of Blender.
But over time as Blender releases new versions, the Blender API changes, leading to the addon to eventually breaking and stop working.

Currently there's no native testing environment that:

What does blender-addon-tester do

This python module allows command line pytesting to be performed on different versions of blender. It will:

Once the addon has been completed and the tests have been written, they are checked in to github.
They can be run against a continous integration tool.
There's currently support for both Github Actions and Travis CI.

Usage

It can be confusing with blender as it has an internal version of python that is different from the system python.
blender-addon-tester is install to the system python and is used to call different versions of blender.
It is inside this instance of blender that the addon under test gets installed.

blender-addon-tester can be install from pypi:

pip install blender-addon-tester

Then it can be called from any script:

    import blender_addon_tester as BAT
    BAT.test_blender_addon(addon_path=addon, blender_revision=blender_rev)

Once called, it will

Online continuous integration and code coverage need to be setup explictly.

pytest

Example output of a successful pytest.

============================= test session starts =============================
platform win32 -- Python 3.7.4, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- C:\blender\blender-2.93\blender.exe
cachedir: .pytest_cache
rootdir: C:\blender\blender-fake-addon
plugins: cov-2.8.1
collected 2 items

tests/test_version.py::test_versionID_pass PASSED                         [ 50%]
tests/test_version.py::test_versionID_fail PASSED                         [100%]

========================== 2 passed in 0.20 seconds ===========================

Example of a failing pytest.

_____________________________ test_versionID_pass ______________________________
bpy_module = 'fake_addon'
    def test_versionID_pass(bpy_module):
        expect_version = (1, 0, 1)
        return_version = get_version(bpy_module)
>       assert  expect_version == return_version
E       assert (1, 0, 1) == (0, 0, 1)
E         At index 0 diff: 1 != 0
E         Use -v to get the full diff
tests/test_pytest.py:11: AssertionError
====================== 1 failed, 1 passed in 0.08 seconds ======================

Operational

To see a working addon environment checkout this repo. In the sub directory examples\testing-fake-addon, it contains a dummy addon that that can be sued to verify that the whole enviroment is setup correctly.

cd examples\testing-fake-addon
test_addon_blender.py fake_addon 3.2

However it is better to use this modile with an addon in a different repo. Check out this repo for that example, fake_addon

Projects using blender-addon-tester

Releases

v0.10

v0.9

v0.8

v0.7

v0.6

v0.5

v0.4

v0.3

v0.2

v0.1