0

Imagine that we have a module one.py with some global variable glob_var=object(). Also I have some other modules on different levels that import glob_var using relative import, such as:

  • from .one.py import glob_var
  • from ..one.py import glob_var
  • from ...one.py import glob_var

I want to patch this glob_var once, instead of patching three times for those modules that imports the variable. Is it possible to implement?

P.S. It's not necessarily to be a global variable. It can be a function or other object

hasam
  • 155
  • 1
  • 6
  • Make a setter function for it, import and call it in any module that you want to patch from. – Jacques de Hooge Oct 15 '16 at 14:09
  • Why are you testing several modules at once? It sounds like your design doesn't isolate them sufficiently. – jonrsharpe Oct 15 '16 at 14:09
  • @jonrsharpe the reason that I have some big project, and this `glob_var` is an instance of some class that makes some stuff that slows down my testing and I just want to patch it when debugging functionality. – hasam Oct 15 '16 at 14:14
  • *"some class that makes some stuff"*?! Any chance of a [mcve]? – jonrsharpe Oct 15 '16 at 14:17

0 Answers0