Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amotl opened this issue Nov 2, 2024 · 0 comments

Comments

@amotl
Copy link
Member

amotl commented Nov 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant