title: Calling unittest.main() in PyCharm - AtrributeError: module '__main__' has no atrribute
body: <p>I think this is more a PyCharm question than unittest question, but I'm studying testing from a book and this example is failing me as written.  I'm running PyCharm 2016.3.2 and Python 3.6</p>
  
  <pre><code>import unittest
  from name_function import get_formatted_name
  
  class NamesTestCase(unittest.TestCase):
      """Tests for 'name_function.py'."""
  
      def test_first_last_name(self):
          """Do names like 'Janis Joplin' work?"""
          formatted_name = get_formatted_name('janis', 'joplin')
          self.assertEqual(formatted_name, 'Janis Joplin')
  
  # In book, it's just the unittest.main() , which does not work...
  # So in PyCharm __name__ doesn't equal __main__ ... not sure why
  # if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>Here is name_function.py:</p>
  
  <pre><code>def get_formatted_name(first, last):
      """Generate a neatly formatted full name."""
      full_name = first + " " + last
      return full_name.title()
  </code></pre>
  
  <p>If I run it as written, I get the following error:</p>
  
  <pre><code>EE
  ======================================================================
  ERROR: test_name_function (unittest.loader._FailedTest)
  ----------------------------------------------------------------------
  AttributeError: module '__main__' has no attribute 'test_name_function'
  
  ======================================================================
  ERROR: true (unittest.loader._FailedTest)
  ----------------------------------------------------------------------
  AttributeError: module '__main__' has no attribute 'true'
  
  ----------------------------------------------------------------------
  Ran 2 tests in 0.000s
  </code></pre>
  
  <p>If I let the "if" statement run (or just delete the call to unittest.main()) then it works properly, with no main() call at all.</p>
  
  <p>This is all in a <code>test_name_function.py</code>.  So it seems like when running this one file (and importing <code>name_function.py</code>) that PyCharm does not consider this one file to be <code>__main__</code> ?  Is PyCharm doing something else behind the scenes? </p>
  
  <p>I'm new to Python and PyCharm and trying to get my head around the structure and environment.  Thanks very much guys.</p>