From 4756eca11e37d188ca4514a7c2404dea13d2be6c Mon Sep 17 00:00:00 2001 From: nharris Date: Wed, 21 Sep 2022 15:26:23 -0600 Subject: [PATCH] - Skip tests if Plex environmental variables are not set --- tests/setup.py | 7 +++++++ tests/test_dizquetv.py | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/setup.py b/tests/setup.py index bf43ab3..8e0e51b 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -24,6 +24,13 @@ def client() -> dizqueTV.API: return dizqueTV.API(url=url, verbose=True) +def _plex_vars_exist() -> bool: + load_dotenv() + url = os.getenv("PLEX_URL") + token = os.getenv("PLEX_TOKEN") + return url is not None and token is not None + + def _make_plex_utils() -> dizqueTV.PlexUtils: load_dotenv() url = os.getenv("PLEX_URL") diff --git a/tests/test_dizquetv.py b/tests/test_dizquetv.py index 00c29e4..261b15b 100644 --- a/tests/test_dizquetv.py +++ b/tests/test_dizquetv.py @@ -3,13 +3,15 @@ import pytest import dizqueTV -from tests.setup import (client, fake_plex_server, plex_server, +from tests.setup import (client, + fake_plex_server, + plex_server, + _plex_vars_exist, plex_server_as_dizquetv_server) REAL_PLEX_SERVER_ADDED = False -@pytest.fixture() def use_real_plex(): if not client().get_plex_server(plex_server().friendlyName): yield client().add_plex_server_from_plexapi(plex_server()) @@ -17,6 +19,10 @@ def use_real_plex(): yield client().get_plex_server(plex_server().friendlyName) +def should_use_real_plex() -> bool: + return _plex_vars_exist() + + class TestGeneral: def test_dizquetv_server_details(self): details = client().dizquetv_server_details @@ -124,7 +130,9 @@ def test_delete_plex_server(self): class TestWithRealPlex: - def test_use_real_plex(self, use_real_plex): + def test_use_real_plex(self): + if not should_use_real_plex(): + pytest.skip("No real Plex server found") server = use_real_plex assert server is not None assert type(server) == dizqueTV.PlexServer