title: Is "if __name__ == '__main__'" required in a __main__.py?
body: <p>In a project that has a <code>__main__.py</code>, rather than</p>
  
  <pre><code># __main__.py
  # def main...
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>...is it OK to just do:</p>
  
  <pre><code># __main__.py
  # def main...
  
  main()
  </code></pre>
  
  <p>Edit:</p>
  
  <p>@user2357112-supports-Monica's argument made a lot of sense to me, so I went back and tracked down the library that had been giving me issues, causing me to still be adding the <code>if __...</code> line. It's upon calling <code>python -m pytest --doctest-modules</code>. </p>
  
  <p>Maybe that's the only place that makes a mistake in running <code>__main__.py</code>? And maybe that's a bug?</p>
  
  <p>Reproduced by putting the first example in the <a href="https://docs.python.org/3/library/argparse.html" rel="noreferrer">docs</a> in a <code>__main__.py</code>:</p>
  
  <pre><code>――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― package/__main__.py ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  package/__main__.py:58: in &lt;module&gt;
      args = parser.parse_args()
  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py:1755: in parse_args
      args, argv = self.parse_known_args(args, namespace)
  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py:1787: in parse_known_args
      namespace, args = self._parse_known_args(args, namespace)
  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py:2022: in _parse_known_args
      ', '.join(required_actions))
  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py:2508: in error
      self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py:2495: in exit
      _sys.exit(status)
  E   SystemExit: 2
  --------------------------------------------------------------------------------------- Captured stderr ---------------------------------------------------------------------------------------
  usage: pytest.py [-h] [--sum] N [N ...]
  pytest.py: error: the following arguments are required: N
  
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  
  Results (4.23s):
  </code></pre>