aboutsummaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-04-13 20:12:32 +0200
committerDaniel Schadt <kingdread@gmx.de>2023-04-13 20:12:32 +0200
commitbe05f4d4e1729714ffb4c3c37b5dcedcd7c79c26 (patch)
treed1d444cbcb934b85dc59a7e8e18568614a8e2610 /tests/conftest.py
parentc6ba50be205763342992fdddad6ca59755051dd9 (diff)
parent5b051b9f97892784d281556db3d5f8b01671568d (diff)
downloadfietsboek-be05f4d4e1729714ffb4c3c37b5dcedcd7c79c26.tar.gz
fietsboek-be05f4d4e1729714ffb4c3c37b5dcedcd7c79c26.tar.bz2
fietsboek-be05f4d4e1729714ffb4c3c37b5dcedcd7c79c26.zip
Merge branch 'profiles'
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index a499bec..d4394cd 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -12,7 +12,7 @@ import pytest
import transaction
import webtest
-from sqlalchemy import delete, select
+from sqlalchemy import delete, inspect, select
from fietsboek import main, models
from fietsboek.data import DataManager
@@ -59,12 +59,18 @@ def data_manager(app_settings):
def _cleanup_data(app_settings):
yield
engine = models.get_engine(app_settings)
+ db_meta = inspect(engine)
with engine.begin() as connection:
for table in reversed(Base.metadata.sorted_tables):
- connection.execute(table.delete())
- data_dir = Path(app_settings["fietsboek.data_dir"])
- if (data_dir / "tracks").is_dir():
- shutil.rmtree(data_dir / "tracks")
+ # The unit tests don't always set up the tables, so be gentle when
+ # tearing them down
+ if db_meta.has_table(table.name):
+ connection.execute(table.delete())
+ # The unit tests also often don't have a data directory, so be gentle here as well
+ if "fietsboek.data_dir" in app_settings:
+ data_dir = Path(app_settings["fietsboek.data_dir"])
+ if (data_dir / "tracks").is_dir():
+ shutil.rmtree(data_dir / "tracks")
@pytest.fixture(scope='session')
def app(app_settings, dbengine, tmp_path_factory):