Skip to content

Commit

Permalink
fixed #26
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Oct 30, 2023
1 parent 02db1b0 commit dc3efa1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
11 changes: 11 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Test suite shared objects and setup """
import os

import pytest


Expand Down
22 changes: 20 additions & 2 deletions tests/test_bbconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit dc3efa1

Please sign in to comment.