re-import module-under-test to lose context

后端 未结 2 1579
情歌与酒
情歌与酒 2021-01-04 10:52

Many Python modules preserve an internal state without defining classes, e.g. logging maintains several loggers accessible via getLogger().

2条回答
  •  不知归路
    2021-01-04 11:35

    This will reimport the module as new for you:

    import sys
    del sys.modules['my_module']
    import my_module
    

提交回复
热议问题