Skip to content

Commit

Permalink
unit test: ensure different project uses different in-memory database
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrabel committed Oct 28, 2023
1 parent a288c22 commit fd89af7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ropetest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def project():
testutils.remove_project(project)


@pytest.fixture
def project2():
project = testutils.sample_project("another_project")
yield project
testutils.remove_project(project)


@pytest.fixture
def project_path(project):
yield pathlib.Path(project.address)
Expand Down
11 changes: 8 additions & 3 deletions ropetest/contrib/autoimport/autoimporttest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sqlite3

from contextlib import closing, contextmanager
from textwrap import dedent
from unittest.mock import ANY, patch
Expand Down Expand Up @@ -26,15 +28,18 @@ def database_list(connection):
return list(connection.execute("PRAGMA database_list"))


def test_in_memory_database_share_cache(project):
def test_in_memory_database_share_cache(project, project2):
ai1 = AutoImport(project, memory=True)
ai2 = AutoImport(project, memory=True)

ai3 = AutoImport(project2, memory=True)

with ai1.connection:
ai1.connection.execute("CREATE TABLE shared(data)")
ai1.connection.execute("INSERT INTO shared VALUES(28)")
res = ai2.connection.execute("SELECT data FROM shared")
assert res.fetchone() == (28,)
assert ai2.connection.execute("SELECT data FROM shared").fetchone() == (28,)
with pytest.raises(sqlite3.OperationalError, match="no such table: shared"):
ai3.connection.execute("SELECT data FROM shared").fetchone()


def test_autoimport_connection_parameter_with_in_memory(
Expand Down

0 comments on commit fd89af7

Please sign in to comment.