Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

unittest, 抽取 conftest.py, 集成 unittest 基础配置 #26

@itaa

Description

@itaa

unittest, 抽取 conftest.py, 集成 unittest 基础配置
目前自动生成的 conftest.py 内容如下,该部分需提取到 summer 内,用户使用的时候直接 import 即可

import os
import pytest
import tempfile
from application.router import app as testapp
from application import db, engine, Base


@pytest.fixture
def app():
    db_fd, db_path = tempfile.mkstemp()
    yield testapp, db_path
    os.close(db_fd)
    os.unlink(db_path)


@pytest.yield_fixture()
def db():
    Base.metadata.create_all(engine)
    yield db
    Base.metadata.drop_all(engine)


@pytest.yield_fixture
def client(app):
    with app[0].test_client() as cli:
        yield cli

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions