title: How to run unittest discover from "python setup.py test"?
body: <p>I'm trying to figure out how to get <code>python setup.py test</code> to run the equivalent of <code>python -m unittest discover</code>.  I don't want to use a run_tests.py script and I don't want to use any external test tools (like <code>nose</code> or <code>py.test</code>).  It's OK if the solution only works on python 2.7.</p>
  
  <p>In <code>setup.py</code>, I think I need to add something to the <code>test_suite</code> and/or <code>test_loader</code> fields in config, but I can't seem to find a combination that works correctly:</p>
  
  <pre><code>config = {
      'name': name,
      'version': version,
      'url': url,
      'test_suite': '???',
      'test_loader': '???',
  }
  </code></pre>
  
  <p><strong>Is this possible using only <code>unittest</code> built into python 2.7?</strong></p>
  
  <p>FYI, my project structure looks like this:</p>
  
  <pre><code>project/
    package/
      __init__.py
      module.py
    tests/
      __init__.py
      test_module.py
    run_tests.py &lt;- I want to delete this
    setup.py
  </code></pre>
  
  <p><strong>Update</strong>: This is possible with <code>unittest2</code> but I want find something equivalent using only <code>unittest</code></p>
  
  <p>From <a href="https://pypi.python.org/pypi/unittest2" rel="noreferrer">https://pypi.python.org/pypi/unittest2</a></p>
  
  <blockquote>
    <p>unittest2 includes a very basic setuptools compatible test collector. Specify test_suite = 'unittest2.collector' in your setup.py. This starts test discovery with the default parameters from the directory containing setup.py, so it is perhaps most useful as an example (see unittest2/collector.py).</p>
  </blockquote>
  
  <p>For now, I'm just using a script called <code>run_tests.py</code>, but I'm hoping I can get rid of this by moving to a solution that only uses <code>python setup.py test</code>.</p>
  
  <p>Here's the <code>run_tests.py</code> I'm hoping to remove:</p>
  
  <pre><code>import unittest
  
  if __name__ == '__main__':
  
      # use the default shared TestLoader instance
      test_loader = unittest.defaultTestLoader
  
      # use the basic test runner that outputs to sys.stderr
      test_runner = unittest.TextTestRunner()
  
      # automatically discover all tests in the current dir of the form test*.py
      # NOTE: only works for python 2.7 and later
      test_suite = test_loader.discover('.')
  
      # run the test suite
      test_runner.run(test_suite)
  </code></pre>