Skip to content

Commit

Permalink
Add test guaranteed to trigger a SQLAlchemy db connection.
Browse files Browse the repository at this point in the history
Augment django_db_setup fixture to add sqlalchemy connection cleanup.
  • Loading branch information
rtibbles committed May 12, 2021
1 parent d56d6b6 commit aebe197
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 13 additions & 3 deletions kolibri/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@
TEMP_KOLIBRI_HOME = "./.pytest_kolibri_home"


@pytest.fixture(scope="session")
def django_db_setup(
request,
django_db_setup,
):
def dispose_sqlalchemy():
from kolibri.core.tasks.main import connection

connection.dispose()

request.addfinalizer(dispose_sqlalchemy)


@pytest.fixture(scope="session", autouse=True)
def global_fixture():
if not os.path.exists(TEMP_KOLIBRI_HOME):
os.mkdir(TEMP_KOLIBRI_HOME)
if not os.path.exists(os.path.join(TEMP_KOLIBRI_HOME, "content")):
os.mkdir(os.path.join(TEMP_KOLIBRI_HOME, "content"))
yield # wait until the test ended
from kolibri.core.tasks.main import connection

connection.dispose()
if os.path.exists(TEMP_KOLIBRI_HOME):
try:
shutil.rmtree(TEMP_KOLIBRI_HOME)
Expand Down
8 changes: 8 additions & 0 deletions kolibri/core/tasks/test/test_no_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest


@pytest.mark.django_db
def test_importing_queue_no_open_connection():
from kolibri.core.tasks.main import queue

queue.empty()

0 comments on commit aebe197

Please sign in to comment.