Traceback (most recent call last):
File "/Applications/PyCharm.app/helpers/pycharm/django_test_manage.py",
line 127, in <module>
utility.execute()
File "/Applications/PyCharm.app/helpers/pycharm/django_test_manage.py",
line 102, in execute
PycharmTestCommand().run_from_argv(self.argv)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 50, in
run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File "/Applications/PyCharm.app/helpers/pycharm/django_test_manage.py",
line 89, in handle
failures = TestRunner(test_labels, verbosity=verbosity,
interactive=interactive, failfast=failfast)
File "/Applications/PyCharm.app/helpers/pycharm/django_test_runner.py",
line 228, in run_tests
extra_tests=extra_tests, **options)
File "/Applications/PyCharm.app/helpers/pycharm/django_test_runner.py",
line 128, in run_tests
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels,
extra_tests, **kwargs)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Applications/PyCharm.app/helpers/pycharm/django_test_runner.py",
line 92, in build_suite
suite = super(DjangoTeamcityTestRunner, self).build_suite(*args,
**kwargs)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/test/runner.py", line 95, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py",
line 204, in discover
tests = list(self._find_tests(start_dir, pattern))
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/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
'/Users/gene/Python/dd_django/pacer/tests'. Expected
'/Users/gene/Python/dd_django/pacer'. Is this module globally installed?
--
Ticket URL: <https://code.djangoproject.com/ticket/22945>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
One more note -- changing the 'tests' directory to anything other than
'tests' resolves the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:1>
Old description:
New description:
--
Comment (by aaugustin):
The problem seems to be that:
- you have a structure like pacer/tests/tests and both tests directories
are on PYTHONPATH, or
- you have a structure like pacer/tests/tests.py and the the tests
directory and the tests.py module are on PYTHONPATH.
Can you check that?
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:2>
Comment (by gene.dolgin@…):
The folder structure is the following: ~/dd_django/pacer/tests/ where
pacer is an app directory with all of the normal stuff (models, admin,
views, etc.)
Within /tests there are: __init__.py and test_models.py
The former is empty. The latter is a number of TestCase subclasses to test
models within /pacer
settingy.py is, other than adding the pacer app and a few niceties, out-
of-the-box standard.
I'm running in a virtualenv as well, created using virtualenvwrapper. This
is standard as well, with no modifications to activate or
activate_this.py.
The test runner is being initialized as:
/Users/gene/Python/venvs/dd_django/bin/python
/Applications/PyCharm.app/helpers/pycharm/django_test_manage.py test pacer
/Users/gene/Python/dd_django
which makes me think that it may be a pycharm problem...
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:3>
Comment (by aaugustin):
Can you reproduce the issue without PyCharm?
Have you tried reporting it to the PyCharm developers?
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:4>
Comment (by gene.dolgin@…):
Reproduced bug without any PyCharm interaction, running 'test' admin task
from manage.py. Same error.
$ python manage.py test
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 50, in
run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Users/gene/Python/venvs/dd_django/lib/python2.7/site-
packages/django/test/runner.py", line 95, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py",
line 204, in discover
tests = list(self._find_tests(start_dir, pattern))
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py",
line 285, in _find_tests
for test in self._find_tests(full_path, pattern):
File
"/System/Library/Frameworks/Python.framework/Versions/2.7/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
'/Users/gene/Python/dd_django/pacer/tests'. Expected
'/Users/gene/Python/dd_django/pacer'. Is this module globally installed?
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:5>
Comment (by timo):
Please use formatting for tracebacks (Aymeric and I edited your previous
posts).
I couldn't reproduce this by modifying the tutorial like this:
{{{
mysite/
polls/
tests/
__init__.py
test_foo.py (originally polls/tests.py)
}}}
{{{
$ python manage.py test
Creating test database for alias 'default'...
..........
----------------------------------------------------------------------
Ran 10 tests in 0.030s
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:6>
Comment (by prestontimmons):
Do you have a tests.py or a tests.pyc in the pacer directory by any
chance?
I can recreate the error with this structure:
{{{
tmp/
__init__.py
tests.py
tests/
__init__.py
test_foo.py
}}}
And by running `python -m unittest discover tmp`.
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:7>
Comment (by gene.dolgin@…):
Yes! Very embarrassed. Can't believe I missed that in the directory tree!
Ran it again and was able to reproduce, and solve the problem.
So, not sure if this is then a bug or not, but that seems to be the issue.
Sorry to send this to the bug tracker without doing enough digging on my
own.
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:8>
* status: new => closed
* resolution: => invalid
Comment:
Closing this issue; prestontimmons' ability to reproduce using `python -m
unittest discover tmp` reveals that this is a behavior of Python's
unittest module discovery, not an issue in Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:9>
Comment (by beruic):
Should there perhaps be a ticket for improving the error message this
results in?
I just spent a lot of time figuring this out. I won't do that again, but
to new developers, this could be a tremendous help the first time.
Perhaps this should be a general check every time Django tries to load
models, test, or other. In debug mode only of course.
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:10>
Comment (by timgraham):
The error message comes from Python, not Django. Without diving into the
unittest discovery code, it's not obvious to me if the error message could
be improved.
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:11>
Comment (by mitar):
I had the same problem, with the following structure:
{{{
missing/
__init__.py
test.py
tests/
__init__.py
test_missing.py
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:12>
* cc: mmitar@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/22945#comment:13>