crate / crate/cratedb-examples

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

Open
#708 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
22
Forks
12
Avg merge
5d 12h
Merged PRs (30d)
22

Description

## 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](https://github.com/crate/cratedb-examples/tree/main/testing/native/python-pytest).

```python
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
- https://github.com/crate/cratedb-examples/pull/707#discussion_r1826593731

## 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.