py.test 기반 테스트 사례를 작성하려고합니다. '모듈'개체가 어떤 속성 '의 getItem'아래오류 발생 TypeError : 'module'객체에 '__getitem__'속성이 없습니다.
가 없습니다 : 내 test.py는
import os
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
basedir = os.path.abspath(os.path.dirname(__file__))
CSRF_ENABLED = True
SECRET_KEY = 'you-will-never-guess'
SQLALCHEMY_DATABASE_URI = 'postgresql://sanjeev:[email protected]:5432/app'
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')
하지만 오류 형식 오류를 얻고있다처럼
!flask/bin/python
import pytest
import config
@pytest.fixture
def app(request):
SQLALCHEMY_DATABASE_URI = 'postgresql://sanjeev:[email protected]:5432/app'
config[SQLALCHEMY_DATABASE_URI]
db.create_all()
def fin():
db.session.remove()
db.drop_all()
request.addfinalizer(fin)
def test_foo(app):
pass
내 config.py 파일이 보이는 것입니다 오류 로그 추적
ERROR at setup of test_foo
request = <SubRequest 'app' for <Function 'test_foo'>>
@pytest.fixture
def app(request):
SQLALCHEMY_DATABASE_URI = 'postgresql://sanjeev:[email protected]:5432/app'
config[SQLALCHEMY_DATABASE_URI]
TypeError: 'module' object has no attribute '__getitem__'
test.py:20: TypeError
[6, 7, 8]
당신이 정확한 스택 추적을 공유 할 수 인쇄해야? 특정 표현식과 코드 라인을 참조 할 수 있습니다. –로그 추적이 추가되었습니다. py.test를 사용하여 setup 및 teardown 메소드를 작성하려고합니다. –