I am running numerous unit tests using pytest
and have several types of database interactions occurring in each unit test module.
My ideal goal is to setup a single sqlite:///:memory:
environment with tables pre-created, data inserted, etc only once (instead of doing this once for each module) that can be shared among my entire test suite, but I am just not sure how to do this properly.
Here is a sample of the tests
package.
$ tree tests/
tests
├── __init__.py
├── conftest.py
├── test_thing1.py
├── test_thing2.py
└── test_thing3.py
I saw this related question but I would prefer to use sqlite in-memory for the obvious performance gains.
My conftest.py
current contains:
@pytest.fixture(scope="session")
def test_db():
"""Returns an object for which a SqlAlchemy engine and session object can be obtained"""
yield DatabaseThing(**db_conf)