Skip to content

Commit

Permalink
Use unique in-memory database name for each SQLite test
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Aug 29, 2023
1 parent 1d30e39 commit 2d0fc8d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,10 @@ async def test_mapping_property_interface(database_url):

@async_adapter
async def test_should_not_maintain_ref_when_no_cache_param():
async with Database("sqlite:///file::memory:", uri=True) as database:
async with Database(
"sqlite:///file::memory:test_should_not_maintain_ref_when_no_cache_param",
uri=True,
) as database:
query = sqlalchemy.schema.CreateTable(notes)
await database.execute(query)

Expand All @@ -1561,7 +1564,10 @@ async def test_should_not_maintain_ref_when_no_cache_param():

@async_adapter
async def test_should_maintain_ref_when_cache_param():
async with Database("sqlite:///file::memory:?cache=shared", uri=True) as database:
async with Database(
"sqlite:///file::memory:test_should_maintain_ref_when_cache_param?cache=shared",
uri=True,
) as database:
query = sqlalchemy.schema.CreateTable(notes)
await database.execute(query)

Expand All @@ -1577,7 +1583,10 @@ async def test_should_maintain_ref_when_cache_param():

@async_adapter
async def test_should_remove_ref_on_disconnect():
async with Database("sqlite:///file::memory:?cache=shared", uri=True) as database:
async with Database(
"sqlite:///file::memory:test_should_remove_ref_on_disconnect?cache=shared",
uri=True,
) as database:
query = sqlalchemy.schema.CreateTable(notes)
await database.execute(query)

Expand All @@ -1588,7 +1597,10 @@ async def test_should_remove_ref_on_disconnect():
# Run garbage collection to reset the database if we dropped the reference
gc.collect()

async with Database("sqlite:///file::memory:?cache=shared", uri=True) as database:
async with Database(
"sqlite:///file::memory:test_should_remove_ref_on_disconnect?cache=shared",
uri=True,
) as database:
query = notes.select()
with pytest.raises(sqlite3.OperationalError):
await database.fetch_all(query=query)
Expand Down

0 comments on commit 2d0fc8d

Please sign in to comment.