fix test behaviour that varies depending on CPython version and py_debug setting
use Py2/3 specific builtin checks in dict.setdefault() optimisation