From 92851a4c7b58cefdb98d6d1a32033d84f82c9f65 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Tue, 31 Dec 2024 10:33:12 +0100 Subject: [PATCH] Revert debug changes and improve TEST_WITH_OPT_DEPS handling --- tests/auxil/envvars.py | 9 ++++++--- tests/ext/test_jobqueue.py | 17 +++++++++-------- tests/ext/test_ratelimiter.py | 2 +- tests/test_bot.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/auxil/envvars.py b/tests/auxil/envvars.py index d9812a43c..07cc2ed29 100644 --- a/tests/auxil/envvars.py +++ b/tests/auxil/envvars.py @@ -27,6 +27,9 @@ def env_var_2_bool(env_var: object) -> bool: return env_var.lower().strip() == "true" -GITHUB_ACTION = os.getenv("GITHUB_ACTION", "") -TEST_WITH_OPT_DEPS = env_var_2_bool(os.getenv("TEST_WITH_OPT_DEPS", "false")) -RUN_TEST_OFFICIAL = env_var_2_bool(os.getenv("TEST_OFFICIAL")) +GITHUB_ACTION: bool = env_var_2_bool(os.getenv("GITHUB_ACTION", "false")) +TEST_WITH_OPT_DEPS: bool = env_var_2_bool(os.getenv("TEST_WITH_OPT_DEPS", "")) or ( + # on local setups, we usually want to test with optional dependencies + not GITHUB_ACTION +) +RUN_TEST_OFFICIAL: bool = env_var_2_bool(os.getenv("TEST_OFFICIAL")) diff --git a/tests/ext/test_jobqueue.py b/tests/ext/test_jobqueue.py index cce364726..33dafb16b 100644 --- a/tests/ext/test_jobqueue.py +++ b/tests/ext/test_jobqueue.py @@ -21,12 +21,13 @@ import calendar import contextlib import datetime as dtm import logging +import platform import time import pytest from telegram.ext import ApplicationBuilder, CallbackContext, ContextTypes, Defaults, Job, JobQueue -from tests.auxil.envvars import TEST_WITH_OPT_DEPS +from tests.auxil.envvars import GITHUB_ACTION, TEST_WITH_OPT_DEPS from tests.auxil.pytest_classes import make_bot from tests.auxil.slots import mro_slots @@ -64,13 +65,13 @@ class TestNoJobQueue: Job(None) -# @pytest.mark.skipif( -# not TEST_WITH_OPT_DEPS, reason="Only relevant if the optional dependency is installed" -# ) -# @pytest.mark.skipif( -# bool(GITHUB_ACTION and platform.system() in ["Windows", "Darwin"]), -# reason="On Windows & MacOS precise timings are not accurate.", -# ) +@pytest.mark.skipif( + not TEST_WITH_OPT_DEPS, reason="Only relevant if the optional dependency is installed" +) +@pytest.mark.skipif( + GITHUB_ACTION and platform.system() in ["Windows", "Darwin"], + reason="On Windows & MacOS precise timings are not accurate.", +) @pytest.mark.flaky(10, 1) # Timings aren't quite perfect class TestJobQueue: result = 0 diff --git a/tests/ext/test_ratelimiter.py b/tests/ext/test_ratelimiter.py index 8af1e5411..56975b1cb 100644 --- a/tests/ext/test_ratelimiter.py +++ b/tests/ext/test_ratelimiter.py @@ -142,7 +142,7 @@ class TestBaseRateLimiter: not TEST_WITH_OPT_DEPS, reason="Only relevant if the optional dependency is installed" ) @pytest.mark.skipif( - bool(GITHUB_ACTION and platform.system() == "Darwin"), + GITHUB_ACTION and platform.system() == "Darwin", reason="The timings are apparently rather inaccurate on MacOS.", ) @pytest.mark.flaky(10, 1) # Timings aren't quite perfect diff --git a/tests/test_bot.py b/tests/test_bot.py index ec17ca89b..07d72fcf5 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -154,7 +154,7 @@ def inline_results(): BASE_GAME_SCORE = 60 # Base game score for game tests xfail = pytest.mark.xfail( - bool(GITHUB_ACTION), # This condition is only relevant for github actions game tests. + GITHUB_ACTION, # This condition is only relevant for github actions game tests. reason=( "Can fail due to race conditions when multiple test suites " "with the same bot token are run at the same time"