AttributeError : '모듈'개체에 '테스트'속성이 없습니다.
이 명령을 실행하고 있습니다.
python manage.py test project.apps.app1.tests
이 오류가 발생합니다.
AttributeError : '모듈'개체에 '테스트'속성이 없습니다.
아래는 내 디렉토리 구조입니다. 또한 설치된 앱 구성에 app1을 추가했습니다.
Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/username/local/dev/local/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 "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/username/local/dev/local/lib/python2.7/site-packages/django/test/runner.py", line 66, in build_suite
tests = self.test_loader.loadTestsFromName(label)
File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'tests'
디렉토리 구조 :
나는 마침내 다른 문제를 해결하기 위해 그것을 알아 냈습니다. 문제는 내 테스트에서 가져 오기를 찾을 수 없다는 것입니다.
테스트를 가져 오지 못하면 위의 오류가 발생하는 것 같습니다. 이는 테스트 스위트가 손상된 테스트를 가져올 수 없기 때문에 의미가 있습니다. 적어도 내 테스트 파일 내에서 가져 오기를 수정하고 제대로 작동하기 시작했는지 확인했기 때문에 이것이 진행되고 있다고 생각합니다.
테스트 케이스의 유효성을 검사하려면 Python 콘솔에서 테스트 케이스 파일을 가져 오십시오.
예:
from project.apps.app1.tests import *
사용하다:
./manage.py shell
뒤에
import myapp.tests
가져 오기 오류의 특성을 찾으려면
내 경우를 들어, 나는 만들 필요가 빈 __init__.py을 내에서 app/tests
폴더
Steve Bradshaw's example above works for import errors (thanks Steve).
Other type of errors (e.g. ValueError) may also cause
AttributeError: 'module' object has no attribute 'tests'
to see what these errors are
./manage.py shell
from myapp.tests import SomeTestCase
t = SomeTestCase()
I had the same error as Chris. I had deleted an old model, then run tests.py, but another file (views.py) was still trying to import the deleted model.
When I took out the now-obsolete import statement, problem solved.
Make sure that all modules that you are using in your script are not broken. By this I mean check spelling in your import statements.
# invalid import
from app.model.notification import Notification
# valid import
from app.models.notification import Notification
You can test yours modules by executing imports statements in djano's interactive console.
$root@13faefes8: python manage.py shell
Type "help", "copyright", "credits" or "license" for more information (InteractiveConsole)
>>> from app.model.notification import Notification
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named model.notification
According to django document When you run your tests, the default behavior of the test utility is to find all the test cases (that is, subclasses of unittest.TestCase) in any file whose name begins with test, automatically build a test suite out of those test cases, and run that suite.
so try this : python manage.py test tests.py
Got the same error, but checked all the reasons list here, did not fix my problem.
Finally figure it out that, the reason is that the name of one method that imported but not used yet is not correct. Though it is a stupid error, it happens.
I resolved the error "AttributeError: module 'utils' has no attribute 'name_of_my_function' " by fixing a circular import reference. My files manage.py and utils.py each had an import statement pointing at each other.
나는 같은 오류가 있었다. 내 모듈의 이름을 common.py로 지정했지만 이미 다른 common.py 모듈이 있었기 때문입니다. 내가해야 할 일은 모듈의 이름을 바꾸는 것뿐이었습니다.
참고 URL : https://stackoverflow.com/questions/25575073/attributeerror-module-object-has-no-attribute-tests
'IT story' 카테고리의 다른 글
스프링 범위 프록시 빈 (0) | 2020.08.29 |
---|---|
Android 애플리케이션에서 두 개의 SQLite 테이블을 조인하려면 어떻게해야합니까? (0) | 2020.08.29 |
텍스트 상자에서 Enter를 누를 때 HTML 버튼을 트리거하는 방법은 무엇입니까? (0) | 2020.08.29 |
TwoWay 또는 OneWayToSource 바인딩은 읽기 전용 속성에서 작동 할 수 없습니다. (0) | 2020.08.28 |
C # Regex에서 캡처 된 그룹의 이름을 어떻게 얻습니까? (0) | 2020.08.28 |