title: "File not found" using manage.py with pytest-django
body: <p>I have a Django project in which certain environment variables are set in <code>manage.py</code> which later serve as the values defined in <code>settings.py</code>. Therefore, in order to run <a href="https://pytest-django.readthedocs.io/en/latest/" rel="nofollow noreferrer">pytest-django</a>, I'd like to run <code>manage.py</code> first.</p>
  
  <p>I'm trying to follow the instructions in <a href="https://pytest-django.readthedocs.io/en/latest/faq.html#how-can-i-use-manage-py-test-with-pytest-django" rel="nofollow noreferrer">https://pytest-django.readthedocs.io/en/latest/faq.html#how-can-i-use-manage-py-test-with-pytest-django</a>, but I'm running into an unexpected error. I have the following directory structure:</p>
  
  <pre><code>.
  ├── lucy
  │   ├── settings
      │   ├── base.py
      │   ├── development.py
      │   ├── production.py
  │   └── staging.py
  │   ├── staticfiles
  │   ├── urls.py
  │   └── wsgi.py
  ├── lucy_web
  │   ├── __init__.py
  │   ├── actions.py
  │   ├── admin
  │   ├── apps.py
  │   ├── fixtures
  │   ├── forms
  │   ├── lib
  │   ├── management
  │   ├── migrations
  │   ├── models
  │   ├── runner.py
  │   ├── serializers.py
  │   ├── static
  │   ├── templates
  │   ├── templatetags
  │   ├── tests
  │   ├── urls.py
  │   └── views
  ├── manage.py
  ├── pytest.ini
  </code></pre>
  
  <p>The contents of <code>runner.py</code> are taken exactly from the FAQ:</p>
  
  <pre><code>class PytestTestRunner(object):
      """Runs pytest to discover and run tests."""
  
      def __init__(self, verbosity=1, failfast=False, keepdb=False, **kwargs):
          self.verbosity = verbosity
          self.failfast = failfast
          self.keepdb = keepdb
  
      def run_tests(self, test_labels):
          """Run pytest and return the exitcode.
  
          It translates some of Django's test command option to pytest's.
          """
          import pytest
  
          argv = []
          if self.verbosity == 0:
              argv.append('--quiet')
          if self.verbosity == 2:
              argv.append('--verbose')
          if self.verbosity == 3:
              argv.append('-vv')
          if self.failfast:
              argv.append('--exitfirst')
          if self.keepdb:
              argv.append('--reuse-db')
  
          argv.extend(test_labels)
          return pytest.main(argv)
  </code></pre>
  
  <p>Finally, in <code>lucy/settings/base.py</code> I add the following line:</p>
  
  <pre><code>TEST_RUNNER = 'lucy_web.runner.PytestTestRunner'
  </code></pre>
  
  <p>Finally, the <code>pytest.ini</code> file is as in the example in the docs:</p>
  
  <pre><code># -- FILE: pytest.ini (or tox.ini)
  [pytest]
  DJANGO_SETTINGS_MODULE = lucy.settings.production
  # -- recommended but optional:
  python_files = tests.py test_*.py *_tests.py
  </code></pre>
  
  <p>The problem is that <code>pytest</code> doesn't seem able to find the tests. If I run the command</p>
  
  <pre><code>python manage.py test lucy_web.tests
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>(venv) Kurts-MacBook-Pro:lucy-web kurtpeek$ python manage.py test lucy_web.tests
  ============================================ test session starts ============================================
  platform darwin -- Python 3.6.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
  rootdir: /Users/kurtpeek/Documents/Dev/lucy/lucy-web, inifile: pytest.ini
  
  ======================================= no tests ran in 0.00 seconds ========================================
  ERROR: file not found: lucy_web.tests
  </code></pre>
  
  <p>However, if I comment out the <code>TEST_RUNNER</code> line in <code>base.py</code> and run the same command, the tests run successfully:</p>
  
  <pre><code>(venv) Kurts-MacBook-Pro:lucy-web kurtpeek$ python manage.py test lucy_web.tests
  Creating test database for alias 'default'...
  System check identified no issues (0 silenced).
  ....E.F................
  ----------------------------------------------------------------------
  Ran 23 tests in 15.974s
  
  FAILED (failures=1, errors=1)
  Destroying test database for alias 'default'...
  </code></pre>
  
  <p>What am I doing wrong here? Do I need to put <code>runner.py</code> in a different location?</p>