Modifying global variables in Python unittest framework

前端 未结 3 1684
长发绾君心
长发绾君心 2020-12-08 18:48

I am working on a series of unit tests in Python, some of which depend on the value of a configuration variable. These variables are stored in a global Python config file an

3条回答
  •  离开以前
    2020-12-08 19:27

    You code imports MY_CONFIG_VARIABLE into the local scope and then immediately overwrites the name with a different object. That won't change the value in the config module. Try

    import config
    config.MY_CONFIG_VARIABLE = False
    

    instead.

提交回复
热议问题