From dc3efa1d2078fd74b8f53f987e138685a2b81a8d Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Mon, 30 Oct 2023 17:51:23 +0100 Subject: [PATCH] fixed #26 --- tests/README.md | 11 +++++++++++ tests/conftest.py | 1 - tests/test_bbconf.py | 22 ++++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/README.md diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..a619e52 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,11 @@ +# How to setup the test environment + +### To create a test database for testing : + +``` +docker run --rm -it --name pipestat-test \ + -e POSTGRES_USER=postgres \ + -e POSTGRES_PASSWORD=dockerpassword \ + -e POSTGRES_DB=pipestat-test \ + -p 5432:5432 postgres +``` \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index fafba1b..342c1d6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,5 @@ """ Test suite shared objects and setup """ import os - import pytest diff --git a/tests/test_bbconf.py b/tests/test_bbconf.py index 463a602..71700eb 100644 --- a/tests/test_bbconf.py +++ b/tests/test_bbconf.py @@ -3,14 +3,28 @@ import pytest from pipestat import PipestatManager from sqlalchemy.exc import IntegrityError +from sqlmodel import SQLModel, create_engine +from sqlmodel.main import default_registry +import os +import warnings from bbconf import BedBaseConf, get_bedbase_cfg from bbconf.exceptions import * -from sqlmodel import SQLModel, create_engine -from sqlmodel.main import default_registry DB_URL = "postgresql+psycopg2://postgres:dockerpassword@127.0.0.1:5432/pipestat-test" +DATA_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") +pytest_db_skip_reason = "Database is not set up... To run this test, set up the database. Go to test/README.md for more information." + + +def db_setup(): + # Check if the database is setup + try: + BedBaseConf(os.path.join(DATA_PATH, "config.yaml")) + except Exception as err: + warnings.warn(UserWarning(f"{pytest_db_skip_reason}")) + return False + return True class ContextManagerDBTesting: @@ -33,6 +47,10 @@ def __exit__(self, exc_type, exc_value, exc_traceback): self.connection.close() +@pytest.mark.skipif( + not db_setup(), + reason=pytest_db_skip_reason, +) class TestAll: def test_invalid_config(self, invalid_cfg_pth): with ContextManagerDBTesting(DB_URL):