title: Global Reliance Making Unit Testing Impossible
body: <p>Background:
  I am a hobbyist Python coder whose first and only project is a text-based Adventure Game <strong>Engine</strong> (<a href="https://github.com/zig13/scenzig" rel="nofollow noreferrer">https://github.com/zig13/scenzig</a>).
  An Adventure Game is a common first project but I realised I didn't have the creativity to write an adventure so decided instead to write a framework so someone else could do the adventure bit.
  It started out as a monolithic script with no functions - at one point 712 lines long - but as I have learnt Python it has been repeatedly rewritten.</p>
  <p>I recently learned of the concepts of unit testing and logging and I think they would be really helpful to me going forward but I have hit a snag.
  The majority of my functions need access to the Adventure files and/or Character file to function.
  These are accessed as a dictionary (thanks to ConfigObj) and a reference to the dictionaries is passed among the modules like this:</p>
  <pre><code>def GiveAdv(a) :
      global adv
      adv = a
      efunc.GiveAdv(a)
  def GiveChar(c) :
      global char
      char = c
      argsolve.GiveChar(char)
      efunc.GiveChar(c)
  </code></pre>
  <p>i.e. After importing another module, a module passes on it's reference to the adventure files and character files. Later in the same module <code>adv.f['Actions'][str(action)]</code> is used to get the information on a specific action from the Actions file for example.</p>
  <p>I've never liked this but it has been <em>fine</em> until now but is a problem now because:</p>
  <ol>
  <li>I am trying to merge two modules rewriting much from scratch in the process and I have no way of testing as I go as everything is so inter-connected</li>
  <li>Unit testing relies on a function taking arguments and producing outputs but most of mine also expect to have access to information in addition to their arguments</li>
  </ol>
  <p>As I see it, Logging (using the logging module) would require somehow passing a reference to the log file around and I just can't believe that people would resort to my horrible &quot;Give&quot; function solution so there must be a better way.</p>
  <p>What is the Pythonic way of giving disparate modules access to the same information, class instances and loggers?</p>