title: if __name__ == '__main__' not working ipython
body: <p>I'm having trouble getting the <code>if __name == '__main__'</code> trick to work in an IPython, Spyder environment. I've tried every approach given in this thread:
  <a href="https://stackoverflow.com/questions/22923002/if-name-main-in-ipython">if __name__ == &#39;__main__&#39; in IPython</a></p>
  
  <p>Here are my super simplified modules</p>
  
  <p>Module1.py</p>
  
  <pre><code>Class UnitTest():
      print 'Mod1 UnitTest!'
  
  if __name__ == '__main__':
      UnitTest()
  </code></pre>
  
  <p>Module2.py</p>
  
  <pre><code>import Module1
  
  Class UnitTest():
      print 'Mod2 UnitTest!'
  
  if __name__ == '__main__':
      UnitTest()
  </code></pre>
  
  <p>So I run Module2.py and I always am seeing both <code>Mod2 UnitTest</code> and <code>Mod1 UnitTest</code> printed.  These are executing in an IPython kernel.  I want only the <code>Mod2 UnitTest</code> message to display.</p>
  
  <p>Any idea what's up?</p>