Python (Django) build failure

python

#1

Running tests in circle fails with tests incorrectly imported from a virtualenv, (rather than the project,) despite the same command working on my local machine. This is painful to debug in the circle ecosystem; any thoughts on the likely cause of divergence? I have tried hacking a pythonpath in an override of the test call to no avail. A guess in the dark: is circle making bad assumptions given my project’s having a setup.py? This is on a dopey personal blog project, so you can check out the code and inspect it if you want.

Stacktrace:

python test_project/manage.py testTraceback (most recent call last):
  File "test_project/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/test/runner.py", line 531, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/test/runner.py", line 451, in build_suite
    tests = self.test_loader.discover(start_dir=label, **kwargs)
  File "/home/ubuntu/.pyenv/versions/2.7.5/lib/python2.7/unittest/loader.py", line 204, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/home/ubuntu/.pyenv/versions/2.7.5/lib/python2.7/unittest/loader.py", line 285, in _find_tests
    for test in self._find_tests(full_path, pattern):
  File "/home/ubuntu/.pyenv/versions/2.7.5/lib/python2.7/unittest/loader.py", line 265, in _find_tests
    raise ImportError(msg % (mod_name, module_dir, expected_dir))

ImportError:
 'tests' module incorrectly imported from 
'/home/ubuntu/virtualenvs/venv-2.7.5/src/django-basic-blog-master/blog'.
 Expected '/home/ubuntu/django-basic-blog/blog'. Is this module globally
 installed?
python test_project/manage.py test returned exit code 1

Circle config:

machine:
  python:
    version: 2.7.5
test:
  override:
    - python test_project/manage.py test
dependencies:
  override:
    - pip install -r test_project/requirements/test.py; pip install coveralls

PR that is failing.


#2

Sorry for the delay.

Not sure why does the tests module have to be globally installed. Is there any hard requirement for that? Ideally there should be no difference between locally-installed module and the one that’s installed globally.

You could try disabling the virtualenv and seeing if that helps to get the tests running. As I suggest here, you could do the following:

dependencies:
  pre:
    - grep -v "activate" ~/.circlerc > ~/.circlerc

Could you please try that out?


#3

What a curious error.

I found some more information on it here: https://code.djangoproject.com/ticket/22945

Do you have a tests.py in your root directory?


#4

Adding that activate command produced this error output:

grep -v "activate" ~/.circlerc > ~/.circlerc
grep -v "activate" ~/.circlerc > ~/.circlerc returned exit code 2

grep: input file `/home/ubuntu/.circlerc' is also the output
Action failed: grep -v "activate" ~/.circlerc > ~/.circlerc

#5

We did it!

I had a directory called test_project that was apparently breaking the test runner (as noted by @luhn). Renaming that to sample project was half the battle, and adding an explicit pythonpath to the test call was the other:

test:
  override:
    - export PYTHONPATH=`pwd`; python sample_project/manage.py test

Thanks guys!


#6