From 4a803d7e192c200ffb4f06628d51ff24b438e653 Mon Sep 17 00:00:00 2001 From: ShadowTemplate Date: Mon, 22 Dec 2025 12:59:01 +0100 Subject: [PATCH 1/2] Testing skip-secrets on PRs --- tests/conftest.py | 28 ++++++++++++++++++++++++++++ tests/test_dropbox_.py | 4 ++++ tox.ini | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..a5e64c11 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,28 @@ +import os + +import pytest + +REQUIRED_SECRETS = [ + "DISCORD_BOT_TOKEN", + "DROPBOX_APP_KEY", + "DROPBOX_APP_SECRET", + "DROPBOX_REFRESH_TOKEN", + "MTGGOLDFISH_PAUPERFORMANCE_PASSWORD", + "MTGGOLDFISH_PAUPERFORMANCE_USERNAME", + "TWITCH_APP_CLIENT_ID", + "TWITCH_APP_CLIENT_SECRET", + "YOUTUBE_API_KEY", +] + + +def pytest_collection_modifyitems(config, items): + missing = [s for s in REQUIRED_SECRETS if not os.getenv(s)] + + if not missing: + return + + skip_marker = pytest.mark.skip(reason=f"Missing CI secrets: {', '.join(missing)}") + + for item in items: + if "integration" in item.keywords: + item.add_marker(skip_marker) diff --git a/tests/test_dropbox_.py b/tests/test_dropbox_.py index 800cd98a..f2f9120d 100644 --- a/tests/test_dropbox_.py +++ b/tests/test_dropbox_.py @@ -1,12 +1,16 @@ +import pytest + from pauperformance_bot.service.pauperformance.storage.dropbox_ import DropboxService +@pytest.mark.integration def test_list_imported_youtube_videos(): assert any( "Pauperformance" in v for v in DropboxService().list_imported_youtube_videos() ) +@pytest.mark.integration def test_list_imported_mtggoldfish_deck_names(): assert any( "Jund" in d for d in DropboxService().list_imported_mtggoldfish_deck_names() diff --git a/tox.ini b/tox.ini index 6aa9f3d2..11adfccc 100644 --- a/tox.ini +++ b/tox.ini @@ -33,6 +33,8 @@ commands = python setup.py sdist [pytest] +markers = + integration: tests that require external services or secrets addopts = --cov pauperformance_bot --cov pauperformance_bot From b3cfa2923169ea446c57b1645f1be5cd71d37c38 Mon Sep 17 00:00:00 2001 From: ShadowTemplate Date: Mon, 22 Dec 2025 13:15:42 +0100 Subject: [PATCH 2/2] Testing skip-secrets on PRs --- tests/conftest.py | 22 ++++++---------------- tests/test_dropbox_.py | 4 ++-- tox.ini | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a5e64c11..0b71cd39 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,27 +2,17 @@ import pytest -REQUIRED_SECRETS = [ - "DISCORD_BOT_TOKEN", - "DROPBOX_APP_KEY", - "DROPBOX_APP_SECRET", - "DROPBOX_REFRESH_TOKEN", - "MTGGOLDFISH_PAUPERFORMANCE_PASSWORD", - "MTGGOLDFISH_PAUPERFORMANCE_USERNAME", - "TWITCH_APP_CLIENT_ID", - "TWITCH_APP_CLIENT_SECRET", - "YOUTUBE_API_KEY", -] +REQUIRED_SECRETS = "RUN_TESTS_WITH_SECRETS" def pytest_collection_modifyitems(config, items): - missing = [s for s in REQUIRED_SECRETS if not os.getenv(s)] - - if not missing: + if os.getenv(REQUIRED_SECRETS): return - skip_marker = pytest.mark.skip(reason=f"Missing CI secrets: {', '.join(missing)}") + skip_marker = pytest.mark.skip( + reason=f"Excluding tests with secrets (no : {REQUIRED_SECRETS} found)" + ) for item in items: - if "integration" in item.keywords: + if "secrets" in item.keywords: item.add_marker(skip_marker) diff --git a/tests/test_dropbox_.py b/tests/test_dropbox_.py index f2f9120d..94931991 100644 --- a/tests/test_dropbox_.py +++ b/tests/test_dropbox_.py @@ -3,14 +3,14 @@ from pauperformance_bot.service.pauperformance.storage.dropbox_ import DropboxService -@pytest.mark.integration +@pytest.mark.secrets def test_list_imported_youtube_videos(): assert any( "Pauperformance" in v for v in DropboxService().list_imported_youtube_videos() ) -@pytest.mark.integration +@pytest.mark.secrets def test_list_imported_mtggoldfish_deck_names(): assert any( "Jund" in d for d in DropboxService().list_imported_mtggoldfish_deck_names() diff --git a/tox.ini b/tox.ini index 11adfccc..af1a7e08 100644 --- a/tox.ini +++ b/tox.ini @@ -34,7 +34,7 @@ commands = [pytest] markers = - integration: tests that require external services or secrets + secrets: tests that require secrets addopts = --cov pauperformance_bot --cov pauperformance_bot