へっぽこびんぼう野郎のnewbie日記

けろけーろ(´・ω・`)! #vZkt8fc6J

Django, Unittest, AttributeError: 'module' object has no attribute について、3分ハマったので備忘録メモ

結論

パスがおかしい

or

ファイルの中身がおかしい

より細かな調査方法

$ ./manage.py shell
$ import foo.bar.target_source_file
"Error comes up HERE"

このエラーから得られる重要な知見

読み込めてないときは
中身がおかしい、別の場所を示している、別の場所にある、のいずれか。またはその複合したもの

CANNOT READはすべてこれに帰結する。

場所が正しい? -> YES
示している場所が正しい? -> YES
中身が正しい? -> YES
 -> 読み込める

エラー内容

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/test/runner.py", line 209, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/site-packages/django/test/runner.py", line 121, in build_suite
    tests = self.test_loader.loadTestsFromName(label)
  File "/home/vagrant/.pyenv/versions/3.4.2/lib/python3.4/unittest/loader.py", line 114, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_stay_error'