Python (Django) build failure

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 This is on a dopey personal blog project, so you can check out the code and inspect it if you want.


python test_project/ testTraceback (most recent call last):
  File "test_project/", line 10, in <module>
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/", line 350, in execute_from_command_line
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/", line 342, in execute
  File "/home/ubuntu/virtualenvs/venv-2.7.5/lib/python2.7/site-packages/django/core/management/commands/", 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/", 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/", 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/", 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/", 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/", 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/", line 451, in build_suite
    tests =, **kwargs)
  File "/home/ubuntu/.pyenv/versions/2.7.5/lib/python2.7/unittest/", line 204, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/home/ubuntu/.pyenv/versions/2.7.5/lib/python2.7/unittest/", 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/", line 265, in _find_tests
    raise ImportError(msg % (mod_name, module_dir, expected_dir))

 'tests' module incorrectly imported from 
 Expected '/home/ubuntu/django-basic-blog/blog'. Is this module globally
python test_project/ test returned exit code 1

Circle config:

    version: 2.7.5
    - python test_project/ test
    - pip install -r test_project/requirements/; pip install coveralls

PR that is failing.

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:

    - grep -v "activate" ~/.circlerc > ~/.circlerc

Could you please try that out?

What a curious error.

I found some more information on it here:

Do you have a in your root directory?

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

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:

    - export PYTHONPATH=`pwd`; python sample_project/ test

Thanks guys!

1 Like