Skip to content

Commit

Permalink
moves --live pytest logic into noxfile
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Jul 24, 2023
1 parent e2637d8 commit d7a0b00
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 50 deletions.
65 changes: 47 additions & 18 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
"pyodbc==4.0.34",
]

# TODO: ensure it's actually installing the different python versions

def _install(session, integration=False):

def _install(session, integration):
session.install("--editable", ".[dev]")

if integration:
Expand All @@ -46,6 +48,35 @@ def _install(session, integration=False):
)


def _check_sqlalchemy(session, version):
session.run(
"python",
"-c",
(
"import sqlalchemy; "
f"assert int(sqlalchemy.__version__.split('.')[0]) == {version}"
),
)


def _run_unit(session, skip_image_tests):
args = [
"pytest",
"src/tests/",
"--ignore src/tests/integration",
]

if skip_image_tests:
args.extend(
[
"--ignore src/tests/test_ggplot.py",
"--ignore src/tests/test_magic_plot.py",
]
)

session.run(*args)


@nox.session(venv_backend="conda", name=DEV_ENV_NAME)
def setup(session):
print("Installing requirements...")
Expand All @@ -55,45 +86,43 @@ def setup(session):
@nox.session(venv_backend="conda")
def test_unit(session):
"""Run unit tests (SQLAlchemy 2.x)"""
_install(session, integration=False)

# TODO: check sqlalchemy version
SKIP_IMAGE_TEST = "--skip-image-tests" in session.posargs

session.run(
"pytest",
"src/tests/",
"--ignore src/tests/integration",
"--ignore src/tests/test_ggplot.py",
"--ignore src/tests/test_magic_plot.py",
)
_install(session, integration=False)
session.install("sqlalchemy>=2")
_check_sqlalchemy(session, version=2)
_run_unit(skip_image_tests=SKIP_IMAGE_TEST)


@nox.session(venv_backend="conda")
def test_unit(session):
def test_unit_sqlalchemy_one(session):
"""Run unit tests (SQLAlchemy 1.x)"""
SKIP_IMAGE_TEST = "--skip-image-tests" in session.posargs

_install(session, integration=False)
session.install("sqlalchemy<2")

# TODO: check sqlalchemy version
_check_sqlalchemy(session, version=1)
_run_unit(skip_image_tests=SKIP_IMAGE_TEST)


@nox.session(venv_backend="conda")
def test_snowflake(session):
def test_integration_snowflake(session):
"""
Run snowflake tests (NOTE: the sqlalchemy-snowflake driver only works with
SQLAlchemy 1.x)
"""
_install(session, integration=False)
session.install("snowflake-sqlalchemy")
session.run("pytest", "src/tests/integration", "-k", "snowflake")


@nox.session(venv_backend="conda")
def test_postgres(session):
def test_integration(session):
"""Run integration tests (to check compatibility with databases)"""
_install(session, integration=True)
session.run(
"pytest",
"src/tests/integration/test_generic_db_operations.py",
"src/tests/integration",
"-k",
"mysql",
"not snowflake",
)
44 changes: 12 additions & 32 deletions src/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,16 @@ def isolate_connections(monkeypatch):
# connection.ConnectionManager.close_all()


def pytest_addoption(parser):
parser.addoption("--live", action="store_true")


# Skip the test case when live mode is on (with --live arg)
@pytest.fixture(scope="session")
def skip_on_live_mode(pytestconfig):
if pytestconfig.getoption("live"):
pytest.skip("Skip on live mode")


# Skip the test case when live mode is off (without --live arg)
@pytest.fixture(scope="session")
def skip_on_local_mode(pytestconfig):
if not pytestconfig.getoption("live"):
pytest.skip("Skip on local mode")


@pytest.fixture
def get_database_config_helper():
return _testing.DatabaseConfigHelper


"""
Create the temporary folder to keep some static database storage files & destroy later
"""


@pytest.fixture(autouse=True)
def run_around_tests(tmpdir_factory):
"""
Create the temporary folder to keep some static database storage files & destroy later
"""
# Create tmp folder
my_tmpdir = tmpdir_factory.mktemp(_testing.DatabaseConfigHelper.get_tmp_dir())
yield my_tmpdir
Expand Down Expand Up @@ -119,7 +99,7 @@ def tear_down_generic_testing_data(engine, test_table_name_dict):


@pytest.fixture(scope="session")
def setup_postgreSQL(test_table_name_dict, skip_on_live_mode):
def setup_postgreSQL(test_table_name_dict):
with _testing.postgres():
engine = create_engine(
_testing.DatabaseConfigHelper.get_database_url("postgreSQL")
Expand Down Expand Up @@ -158,7 +138,7 @@ def postgreSQL_config_incorrect_pwd(ip_empty, setup_postgreSQL):


@pytest.fixture(scope="session")
def setup_mySQL(test_table_name_dict, skip_on_live_mode):
def setup_mySQL(test_table_name_dict):
with _testing.mysql():
engine = create_engine(
_testing.DatabaseConfigHelper.get_database_url("mySQL"),
Expand Down Expand Up @@ -187,7 +167,7 @@ def ip_with_mySQL(ip_empty, setup_mySQL):


@pytest.fixture(scope="session")
def setup_mariaDB(test_table_name_dict, skip_on_live_mode):
def setup_mariaDB(test_table_name_dict):
with _testing.mariadb():
engine = create_engine(
_testing.DatabaseConfigHelper.get_database_url("mariaDB")
Expand Down Expand Up @@ -216,7 +196,7 @@ def ip_with_mariaDB(ip_empty, setup_mariaDB):


@pytest.fixture(scope="session")
def setup_SQLite(test_table_name_dict, skip_on_live_mode):
def setup_SQLite(test_table_name_dict):
config = _testing.DatabaseConfigHelper.get_database_config("SQLite")

if Path(config["database"]).exists():
Expand Down Expand Up @@ -252,7 +232,7 @@ def ip_with_SQLite(ip_empty, setup_SQLite):


@pytest.fixture(scope="session")
def setup_duckDB_native(test_table_name_dict, skip_on_live_mode):
def setup_duckDB_native(test_table_name_dict):
engine = duckdb.connect(database=":memory:", read_only=False)
return engine

Expand Down Expand Up @@ -300,7 +280,7 @@ def ip_with_duckDB_native(ip_empty, setup_duckDB_native, test_table_name_dict):


@pytest.fixture(scope="session")
def setup_duckDB(test_table_name_dict, skip_on_live_mode):
def setup_duckDB(test_table_name_dict):
config = _testing.DatabaseConfigHelper.get_database_config("duckDB")

if Path(config["database"]).exists():
Expand Down Expand Up @@ -348,7 +328,7 @@ def ip_with_duckdb_sqlalchemy_empty(tmp_empty, ip_empty_testing):


@pytest.fixture(scope="session")
def setup_MSSQL(test_table_name_dict, skip_on_live_mode):
def setup_MSSQL(test_table_name_dict):
with _testing.mssql():
engine = create_engine(_testing.DatabaseConfigHelper.get_database_url("MSSQL"))
# Load pre-defined datasets
Expand Down Expand Up @@ -376,7 +356,7 @@ def ip_with_MSSQL(ip_empty, setup_MSSQL):


@pytest.fixture(scope="session")
def setup_Snowflake(test_table_name_dict, skip_on_local_mode):
def setup_Snowflake(test_table_name_dict):
username = os.getenv("SF_USERNAME")
password = os.getenv("SF_PASSWORD")

Expand Down Expand Up @@ -412,7 +392,7 @@ def ip_with_Snowflake(ip_empty, setup_Snowflake, pytestconfig):


@pytest.fixture(scope="session")
def setup_oracle(test_table_name_dict, skip_on_live_mode):
def setup_oracle(test_table_name_dict):
with _testing.oracle():
engine = create_engine(_testing.DatabaseConfigHelper.get_database_url("oracle"))
engine.connect()
Expand Down

0 comments on commit d7a0b00

Please sign in to comment.