aboutsummaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
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):