작업 테스트 줄을 한 줄씩 복사하고 몇 개의 이름을 변경했습니다 (적어도 생각했습니다). 이제는 매우 알 수없는 오류가 발생합니다. (일부 항목을 FOO, BAR로 대체했습니다)
ImportError: 'tests' module incorrectly imported from 'FOO/exports/tests'. Expected 'FOO/exports'. Is this module globally installed?
문제는 내가 오류를 전혀 이해하지 못한다는 것입니다. 이 오류 메시지는 무엇을 의미합니까?
완전한 스택 트레이스 :
Traceback (most recent call last):
File "BAR/modeling/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/jonathan/anaconda/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 "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/test/runner.py", line 531, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/django/test/runner.py", line 451, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/Users/jonathan/anaconda/lib/python2.7/unittest/loader.py", line 206, in discover
tests = list(self._find_tests(start_dir, pattern))
File "/Users/jonathan/anaconda/lib/python2.7/unittest/loader.py", line 267, in _find_tests
raise ImportError(msg % (mod_name, module_dir, expected_dir))
ImportError: 'tests' module incorrectly imported from 'FOO/exports/tests'. Expected 'FOO/exports'. Is this module globally installed?
답변
내 경험상, 테스트를 실행할 때 이상한 ImportErrors는 테스트 모듈 자체의 ImportError로 인해 발생합니다.
테스트 모듈을 가져올 수 있는지 확인하십시오.
$ python manage.py shell
...
>>> import foo.exports.tests
편집하다:
이로 인해 오류가 발생하면 디렉토리 foo/exports/tests
와 파일 이 모두 없는지 확인하십시오.foo/exports/tests.py
답변
Daniel Hepper가 위의 주석에서 말했듯이 앱에 app/tests
폴더와 app/tests.py
파일 이 모두 있는지 확인 하십시오.
Django startapp
는 tests.py
자동으로 파일을 생성 하므로 인식하지 못한 파일이있을 수 있습니다.
자동으로 생성 된 tests.py
파일을 삭제하기 만하면 작동합니다. (물론 삭제하기 전에 파일의 내용을 확인해야합니다!)
답변
test라는 디렉토리를 만들고 그 안에 test_views.py, test_models.py 등과 같은 테스트 파일을 작성한 경우 ‘python manage.py’명령으로 자동 생성 된 ‘test.py’파일을 제거해야합니다. startapp ‘
답변
가능한 경우 목록에 추가하십시오.
이는 현재 사용중인 패키지가 로컬로 설치된 경우 가상 환경 내에서도 발생할 수 있습니다.
이 경우 “다시 연결”(정확한 용어를 알지 못함)을 설치 한 버전을 개발 명령을 사용하여 제거하면됩니다.
~/dev/stufflib% pip uninstall stufflib
~/dev/stufflib% python setup.py develop
~/dev/stufflib% python setup.py test
답변
제 경우에 문제는 “실제”경로가 아닌 심볼릭 링크에서 프로젝트 폴더로 django 테스트 작업을 시작하려고했기 때문입니다. symlink를 사용하지 않는 프로젝트 폴더에서 django 테스트 작업을 실행할 때이 오류가 발생하지 않습니다.
답변
app/tests
폴더와 app / tests.py 가 모두 있는지 확인하십시오.
앱의 파일.
기본적으로 파일은 자동 tests.py
으로이 파일을 삭제합니다. 오류가 해결됩니다.
답변
