Giter VIP home page Giter VIP logo

blender-addon-tester's Introduction

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:

  • Allows an addon to be tested against multiple versions of blender and multiple OSs (ubuntu, windows and macosx)
  • Used an industry standard of testing, i.e. pytest
  • Plugs into a continuous integration tool, i.e. Github Actions, Travis CI
  • Ability to test a passing addon against the nightly builds, to catch API breaks as close to when they happen
  • Code coverage of the addon. Used to assess comprehensivness of the tests.

What does blender-addon-tester do

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

  • download and maintain different versions of blender locally.
  • install the addon under test into a location accessible by the respective version of blender.
  • execute a series of tests, by default, located in the tests directory. These tests are written in the pytest format.

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

  • Check to see if the version of blender is presnet in the cache location, if not it will download that version of blender and install it to the cache location, installing all the extra python modules required to enable pytest-ing and coverage.
  • It will install the addon to the version of blender
  • It will run all the tests, default tests directory, but this can be explictly set. \it will report a pass or failure. This result is written to be capturable by CI tools.
  • It will also report to coverage of the test. This coverage can be almalgamated across all versions to get a full idea of testing.

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

  • Add support for 3.4
  • Add support for 3.5
  • Bumped all the guthub actions revs
  • Added support for github actions release

v0.9

  • Add support for 3.1
  • Add support for 3.2
  • Add support for 3.3
  • Move to python3.10 on CI

v0.8

  • Needed to updated how the blender packages got fetch from the server (again)
  • Fixed the non-default addon directory option, #26
  • Break out the addon directory setup from the addon install
  • Deprecated 2.79, which removes any dependency on python3.5
  • Deprecated 2.80

v0.7

  • Re-do how the most recent version of Blender is fetched as the format used on the server has changed.
  • Deprecated 2.78.

v0.6

  • Added PYTEST_ARGS on the config option
  • Need a separate PYTHONPATH for the scripts directory that the addon uses for helper scripts:
    addon_helper = os.environ.get("ADDON_TEST_HELPER", None)

v0.5

  • Fix Blender rev edit bug

v0.4

  • Introduce per Blender rev addons support

v0.3

  • New release required due to repo migration

v0.2

  • Added default cache location if not specified
  • Deleted built-in addon from reference Blender if testing a new version of the addon
  • Updated setup.py to remove unnecessary modules needed for blender-addon-tester to work.
  • Updated documentation

v0.1

  • Initial check-in to PyPI
  • Working against GitHub Actions
  • Working against Travis CI

blender-addon-tester's People

Contributors

davekeeshan avatar douglaskastle avatar hannesdelbeke avatar myselfhimself avatar tilix4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

blender-addon-tester's Issues

Application Template support

Being able to run tests for a Blender Application Template would be a great feature for your module.

The main issues are:

  • It will require some design changes.
  • The name won't be accurate anymore.

Blender download retry

Sometimes a download from blender servers fail, due to some server issue. A retry after 5-10 minutes should be implemented to give the server time to recover and not fail the test.

3 time retry should be enough.

Module packaging: define __doc__

help(blender_addon_tester) yields this for now:

Help on package blender_addon_tester:

NAME
    blender_addon_tester

PACKAGE CONTENTS
    addon_helper
    blender_load_pytest
    get_blender
    run_blender

FILE
    /home/AAAAAA/lib/python3.7/site-packages/blender_addon_tester/__init__.py

Use tmp dir or equivalent for downloads

On linux, with blender-addon-tester 0.1 installed in a virtualenv, when trying to run BAT, if in my home directory, since the default download path is ../, I get a permission denied related to writing.
Some sort of temp directory should be decided cross-OSes. Python does have mktemp, but such a temp directory must be redetected / reused somehow every time the script starts again... which might mean using instead home settings.

Windows failure observed on locally run machines (Not CI)

Only happens with the python 3.5 version so 2.78 an 2.79. version 2.80 works fine and above, which has python3.7

Exception:
Traceback (most recent call last):
  File "C:\cygwin64\home\douglas\projects\blender-fake-addon\examples\blender-2.79b-windows64\2.79\python\lib\shutil.py", line 544, in move
    os.rename(src, real_dst)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'c:\\cygwin64\\home\\douglas\\projects\\blender-fake-addon\\examples\\blender-2.79b-windows64\\2.79\\python\\lib\\site-packages\\pip\\_vendor\\requests\\packages\\urllib3\\packages\\ssl_match_hostname\\__pycache__\\__init__.cpython-35.pyc' -> 'C:\\Users\\douglas\\AppData\\Local\\Temp\\pip-e9ejge9c-uninstall\\cygwin64\\home\\douglas\\projects\\blender-fake-addon\\examples\\blender-2.79b-windows64\\2.79\\python\\lib\\site-packages\\pip\\_vendor\\requests\\packages\\urllib3\\packages\\ssl_match_hostname\\__pycache__\\__init__.cpython-35.pyc'

test example-from-github-pip

I am struggling a bit with the test-*-example-from-github-pip.yml. I think it can't work always. Right now it points to a git-repo branch. So that limits other branches from doing iterative work.

When we get pypi support, there will always be a latency issue. Even if published, the module available on pypi might not update for 2 hours, or what ever, so if you have edited a core piece of code you want to test, you might not see it in the length of time it takes for the testing to complete, which looks pretty fast, sub 10 minutes.

This test feels like one that should live with the blender-fake-addon repo, and the other one, with the wheel, lives here.

There is potentially a third/replacement test. One where you just set the PYTHONPATH to the directory with the module lives, or you do a straight python setup install (not with a wheel)

Am I missing something?

Try to validate addon grossly before doing anything

for blender-addon-tester 0.1, when piping a non-plugin path (eg. pictures directory), blender gets downloaded first, then blender detects that it's not a plugin..
We could detect grossly that there are files in it (compressed or uncompressed dir), with one file exposing one type of comment or methods, with a proper directories layout.

Note that such an archive validator could be imitated also to validate that: any plugin is a plugin according to a spec (could be used to check hundreds of them), any blender release is a supported blender release (eg. tar.bz2, tar.gz, tar.xz, dmg, *lender.app with executable in Contents/MacOSX etc..).

Crash with non-text files

In the function clean_file if there is a non-text file in the targeted directory, I get a UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte (in my case it's for a .DS_Store OSX file). I also had the issue with image files.

I don't get what this function is supposed to do and if this issue is actually critical.

Add releases publishing onto pypi.org

For now, we are targetting a Github branch in order for pip install blender_addon_tester to test itself.

Having blender-addon-tester written with hyphens instead of underscores prevents easy import from python, so possibly we should stick to underscores in the setup.py / python packaging as much as possible.

We should:

  • decide on the name and URL on pypi.org: blender_addon_tester
  • decide on a versioning. Eg. start with 0.1
  • write maybe a Github Actions workflow file that pushes a release to pypi.org using Twine when a v* eg. v0.1 tag is pushed (inspired from this workflow file and this send_to_pypi_bash_function)
  • make a more concise README if we plan to use the text for both the pypi.org project page and the Github project home README
  • test that pip installing from upstream does work, from a local a machine and from other Github projects CIs jobs maybe.

For info, after pushing a release to pypi.org, it looks like 30 minutes-2 hours are needed before any pip install grabs that new version

Module packaging: uncallable exported symbols

get_blender, os, run_blender below are probably exported inside the module for no reasons

Python 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import blender_addon_tester as BAT
>>> dir(BAT)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'get_blender', 'os', 'run_blender', 'test_blender_addon']
>>> BAT.get_blender()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> BAT.get_blender
<module 'blender_addon_tester.get_blender' from '/home/jd/.virtualenvs/gmicpy290numpy/lib/python3.7/site-packages/blender_addon_tester/get_blender.py'>
>>> BAT.get_blender("2.80")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

Create a github action that can be used by client scripts

Actions can call actions.

A action should be created here that can be called by clients.

This will allow the bender versions to be added to in the pypi, and this will flow straight through to client testing.

Right now our side maintains a list and their side maintains a list. It works, but can be improved.

Fix code coverage

Code cover in this project is slightly irrelevant. Consider removing.

When this code is being used to enable addon testing, it is the addon that needs the code coverage, not anything from here.

It's presence here might be confusing.

It should definitely be in the new form blender-fake-addon.

Thought?

Enhance to test addons that come with blender

Right now if you try to test an addon that comes with blender there appears to be a race condition on which addon to use. Based on the age of the file on the file system, so the chances of the old addon winning is actually greater.

Need to move existing addon out of the way for testing and return once testing is complete. I would rather not smash delete the old one.

Rewrite rebuild_pipreinstall_and_testexamples.sh in python

rebuild_pipreinstall_and_testexamples.sh does not work in windows land. cmd does not have shell (I am referring to local windows machines, not powershell)

A similar script written in python should work on all systems as python is the only prerequisite required to run the whole show.

Tester is not working

@myselfhimself

OK I decided to test the tester. I introduced and error that should cause every test to fail. However I get green every where, both on travis and github actions:

https://github.com/douglaskastle/blender-addon-tester/runs/537749667?check_suite_focus=true
https://travis-ci.org/github/douglaskastle/blender-addon-tester/builds/667444567

Looking in the test themselves they are failing, it is just that the failure is not percolating out.

This was the whole effort of the original work I did. The error happens in python in blender. That error has to get out of the python, out of blender, out of the wrapper python to the CI tool.

I have not taken your flow apart yet, but I suspect it the the blender to the top level python is where this is not taking place.

I did this inside the pypi-test branch as it was the active one I was on. It has all the work from todays work in macosc-support branch merged into it.

tests/test_version.py::test_versionID_pass FAILED                        [ 50%]
=================================== FAILURES ===================================
_____________________________ test_versionID_pass ______________________________
bpy_module = 'fake_addon'
    def test_versionID_pass(bpy_module):
        expect_version = (0, 1, 1)
        return_version = get_version(bpy_module)
>       assert expect_version == return_version
E       assert (0, 1, 1) == (0, 0, 1)
E         At index 1 diff: 1 != 0
E         Full diff:
E         - (0, 0, 1)
E         ?     ^
E         + (0, 1, 1)
E         ?     ^
tests/test_version.py:13: AssertionError
=========================== short test summary info ============================
FAILED tests/test_version.py::test_versionID_pass - assert (0, 1, 1) == (0, 0...
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
============================== 1 failed in 0.05s ===============================

Run a local Blender

Need

Allowing the user to target a local/custom Blender executable path would make the local development of this addon faster (don't have to download it all the time --which is a great feature by the way--). It would also some CICD pipelines like Gitlab's to use a custom docker image where Blender is already bundled to not overload the bandwidth.

How

Add a blender_path="" parameter to the main function?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.