mardi 2 juin 2020

How to isolate from each other changes of data made by tests in the database?

How to isolate changes of data made by tests in the database?

I've found the solution, but it looks a bit wasteful. On each test, we create a new database and after test drop it:

@pytest.fixture
def database():
    tmp_name = '.'.join([uuid.uuid4().hex, 'pytest'])
    create_database(tmp_url)

    try:
        yield tmp_url
    finally:
        drop_database(tmp_url)

Could someone give me advice, how to isolate tests' data in DB?

Aucun commentaire:

Enregistrer un commentaire