[New-bugs-announce] [issue26643] regrtest: rework libregrtest.save_env submodule

STINNER Victor report at bugs.python.org
Fri Mar 25 14:20:24 EDT 2016

New submission from STINNER Victor:

(I pushed the change 245a16f33c4b, but Serhiy asked me to review it and discuss it. So I reverted my change and created this issue.)

I noticed many times that buildbots log "test xxx changed yyy" but this line is not enough to debug the issue. I propose to always display the old and new value to easy debugging these issues.

Sometimes, I try to reproduce the issue, but I fail to reproduce it locally. I may depend on the test execution order and the platform.

Attached patch changes:

* Replace get/restore methods with a Resource class and Resource subclasses
* Create ModuleAttr, ModuleAttrList and ModuleAttrDict helper classes
* Use __subclasses__() to get resource classes instead of using an hardcoded
  list (2 shutil resources were missinged in the list!)
* Don't define MultiprocessingProcessDangling resource if the multiprocessing module is missing
* Nicer diff for dictionaries. Useful for the big os.environ dict
* Reorder code to group resources

I chose to use classes to be able to easily customize how "Before/After" (value diff) is displayed: the new display_diff() method.

I also wrote helper classes to factorize the code.


    def get_sys_path(self):
        return id(sys.path), sys.path, sys.path[:]
    def restore_sys_path(self, saved_path):
        sys.path = saved_path[1]
        sys.path[:] = saved_path[2]


   class SysPath(ModuleAttrList):
       name = 'sys.path'

When sys.path is modified, currently Python displays the whole (id, object, object_copy) tuple which is not easily readable. With my change, it only displays object_copy (one list).

I began to write a pretty diff for ModuleAttrList, but it looks non trivial, and I'm not sure that it's worth (since lists are quite short).

components: Tests
files: save_env.patch
keywords: patch
messages: 262449
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: regrtest: rework libregrtest.save_env submodule
versions: Python 3.6
Added file: http://bugs.python.org/file42293/save_env.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list