Skip to content

Testing: Add snippet demonstrating CTK's DatabaseAdapter with pytest fixtures #708

@amotl

Description

@amotl

About

That's a reasonable micro-example bearing a fluent API that may deserve to be presented better. The right slot for a snippet would probably be testing/native/python-pytest.

from cratedb_toolkit.io.sql import DatabaseAdapter

HERE = Path(__file__).parent


@pytest.fixture()
def cratedb() -> DatabaseAdapter:
    return DatabaseAdapter(dburi="crate://crate@localhost:4200")


@pytest.fixture(scope="function", autouse=True)
def init_database(cratedb):
    """
    Initialize database.
    """
    cratedb.run_sql("DROP TABLE IF EXISTS time_series_data;")
    cratedb.run_sql((HERE / "init.sql").read_text())

References

Outlook

After slotting it in, based on interests and spirit, such details may also want to be converged into relevant micro-tutorials and/or quick social media posts, à la "Efficient Software Testing with Python and CrateDB".

/cc @simonprickett, @kneth

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