我正在尝试为我的应用程序编写一些测试。我可以测试不包含与db相关的任何内容的URL。
@pytest.fixture
def client():
"""
Load pytest fixture.
:return: test_client()
"""
# yield application.test_client()
db_fd, application.config['DATABASE'] = tempfile.mkstemp()
db.create_all()
application.config['TESTING'] = True
client = application.test_client()
yield client
os.unlink(application.config['DATABASE'])
我的测试文件:
def test_membership_register(client):
"""Test entry point of website."""
rv = client.get('/register')
new_user = User(
username='test_user_1',
email='test_email@test1.com',
password='test1_Password',
)
db.session.add(new_user)
db.session.commit()
assert 200 == rv.status_code
错误:
E sqlalchemy.exc.InvalidRequestError:已为此MetaData实例定义表'membership_user'。指定'extend_existing = True'重新定义现有Table对象上的选项和列。