# HG changeset patch # User Aurelien Campeas # Date 1495442822 -7200 # Mon May 22 10:47:02 2017 +0200 # Node ID 121fe47b5c5299467bb63af3beba170eab998b2d # Parent 083baf174e470120b2afd3bff2fbf80c749463bf doc: provide a small README diff --git a/README.md b/README.md new file mode 100644 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# PYTEST SQLALCHEMY/POSTGRES FIXTURE + + +## AUTOMATIC ENGINE FIXTURE WITH POSTGRES CLUSTER + + +From a conftest.py it is sufficient to write this: + +```python + from pytest_sa_pg import fixture + from myapp import schema + + engine = fixture.engine_fixture(schema.meta, 'data', 5433) +``` + +This creates a session-scoped fixture. + +The postgres database files for the local test cluster will be then +created under `data/pgdb`. + +From this, in test modules, one can use the fixture as such: + +```python + def test_foo(engine): + name = engine.execute('select name from person where person.id = 42').scalar() + assert name == 'Babar' +``` + +## DIRECTLY USING THE POSTGRES CLUSTER HANDLER + + +Sometimes the default fixture is not sufficient (e.g. because one uses +namespace schemas and these are not automatically handled by +sqlalchemy). + +We can use the library as such: + +```python + import pytest + from pytest_sa_pg import db + + @pytest.fixture(scope='session') + def engine(request): + db.setup_local_pg_cluster(request, 'data', 5433) + ... +``` + diff --git a/setup.cfg b/setup.cfg new file mode 100644 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md