The real issue was that symbols returned by the test renderer have not been initialized before being used in symbolForFeature().

Attached (fixed and simplified) version works fine for me - closing as invalid. I have some ideas how the situation could be improved in QGIS 3 so that custom renderer implementations are less crash-prone...