2016-05-30 1 views
11

私はラインでの作業テストラインをコピーしただけ(少なくとも私は思った)いくつかの名前を変更し、今、私はこの非常に不可解なエラーを取得しています"テストモジュールが間違ってインポートされました"とはどういう意味ですか?

ImportError: 'tests' module incorrectly imported from 'FOO/exports/tests'. Expected 'FOO/exports'. Is this module globally installed? 
を(私はFOO、BARでいくつかのものを交換しました)

問題は私がエラーを全く理解していないことです。このエラーメッセージは何を意味しますか?

完全なスタックトレース:私の経験で

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? 
+0

完全なスタックトレースを投稿できますか? –

+0

'test 'をインポートしようとしている構造とファイルをチェックするために、関連するファイルツリーを追加してください。 – trinchet

答えて

48

、奇妙なImportErrors実行中のテストはテストモジュール自体にはImportErrorによって引き起こされます。

あなたのテストモジュールをインポートすることができることを確認します。

$ python manage.py shell 
... 
>>> import foo.exports.tests 

編集:それはエラーが発生した場合

は、あなたがディレクトリfoo/exports/testsとファイルの両方を持っていないことを確認してくださいfoo/exports/tests.py

+0

はい、そのようなモジュールはないと言います。しかし、ファイルはそこにあります。他に何ができますか? – jonalv

+0

'foo'と' exports'の両方が適切なPythonモジュールです、つまり '__init __。py'を含んでいますか? –

+0

はい私は '__init __。py'ファイルを持っていて、エディタ(Eclipse)はフォルダアイコンではなくモジュールアイコンを表示します – jonalv

0

私の場合、問題は、シンボリックリンクから "実際の"パスではなく、プロジェクトのフォルダにdjangoのテストタスクを開始しようとしたためです。 symlinkを使わないプロジェクトフォルダからdjangoテストタスクを実行すると、このエラーは発生しません。

関連する問題