From 9c771dd2180e41601eaf1639bac0a87743a2dd9d Mon Sep 17 00:00:00 2001 From: grqx_wsl <173253225+grqx@users.noreply.github.com> Date: Wed, 23 Apr 2025 14:15:28 +1200 Subject: [PATCH 1/3] add --plugins Co-authored-by: Simon Sawicki <37424085+Grub4K@users.noreply.github.com> --- devscripts/run_tests.py | 11 ++++++++--- test/helper.py | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/devscripts/run_tests.py b/devscripts/run_tests.py index ebb3500b6..cf33d443d 100755 --- a/devscripts/run_tests.py +++ b/devscripts/run_tests.py @@ -19,12 +19,14 @@ def parse_args(): 'test', help='an extractor test, test path, or one of "core" or "download"', nargs='*') parser.add_argument( '-k', help='run a test matching EXPRESSION. Same as "pytest -k"', metavar='EXPRESSION') + parser.add_argument( + '--plugins', help='load plugins', action='store_true') parser.add_argument( '--pytest-args', help='arguments to passthrough to pytest') return parser.parse_args() -def run_tests(*tests, pattern=None, ci=False): +def run_tests(*tests, pattern=None, ci=False, load_plugins=False): # XXX: hatch uses `tests` if no arguments are passed run_core = 'core' in tests or 'tests' in tests or (not pattern and not tests) run_download = 'download' in tests @@ -47,7 +49,10 @@ def run_tests(*tests, pattern=None, ci=False): print(f'Running {arguments}', flush=True) try: - return subprocess.call(arguments) + return subprocess.call(arguments, env={ + **os.environ, + 'YTDLP_NO_PLUGINS': '1' if os.environ.get('YTDLP_NO_PLUGINS') or not load_plugins else '', + }) except FileNotFoundError: pass @@ -72,6 +77,6 @@ def run_tests(*tests, pattern=None, ci=False): args = parse_args() os.chdir(Path(__file__).parent.parent) - sys.exit(run_tests(*args.test, pattern=args.k, ci=bool(os.getenv('CI')))) + sys.exit(run_tests(*args.test, pattern=args.k, ci=bool(os.getenv('CI')), load_plugins=args.plugins)) except KeyboardInterrupt: pass diff --git a/test/helper.py b/test/helper.py index e4cb478e2..72e784ffb 100644 --- a/test/helper.py +++ b/test/helper.py @@ -87,6 +87,8 @@ def report_warning(self, message, *args, **kwargs): def gettestcases(include_onlymatching=False): + import yt_dlp.plugins + yt_dlp.plugins.load_all_plugins() for ie in yt_dlp.extractor.gen_extractors(): yield from ie.get_testcases(include_onlymatching) From d147c9c3691a46447a36c64e9134cf00bbd95676 Mon Sep 17 00:00:00 2001 From: grqx_wsl <173253225+grqx@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:51:33 +1200 Subject: [PATCH 2/3] Don't load plugins by default --- devscripts/run_tests.py | 2 +- test/helper.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/devscripts/run_tests.py b/devscripts/run_tests.py index cf33d443d..e39aa7af0 100755 --- a/devscripts/run_tests.py +++ b/devscripts/run_tests.py @@ -51,7 +51,7 @@ def run_tests(*tests, pattern=None, ci=False, load_plugins=False): try: return subprocess.call(arguments, env={ **os.environ, - 'YTDLP_NO_PLUGINS': '1' if os.environ.get('YTDLP_NO_PLUGINS') or not load_plugins else '', + '_YT_DLP_TEST_DO_LOAD_PLUGINS': '1' if load_plugins else '', }) except FileNotFoundError: pass diff --git a/test/helper.py b/test/helper.py index 72e784ffb..e999993fb 100644 --- a/test/helper.py +++ b/test/helper.py @@ -1,6 +1,7 @@ import errno import hashlib import json +import os import os.path import re import ssl @@ -87,8 +88,9 @@ def report_warning(self, message, *args, **kwargs): def gettestcases(include_onlymatching=False): - import yt_dlp.plugins - yt_dlp.plugins.load_all_plugins() + if os.environ.get('_YT_DLP_TEST_DO_LOAD_PLUGINS'): + import yt_dlp.plugins as plugins + plugins.load_all_plugins() for ie in yt_dlp.extractor.gen_extractors(): yield from ie.get_testcases(include_onlymatching) From a5c7f7fdab3740b758e836868685d565f46ba021 Mon Sep 17 00:00:00 2001 From: grqx_wsl <173253225+grqx@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:16:51 +1200 Subject: [PATCH 3/3] don't always call load_all_plugins --- devscripts/run_tests.py | 2 +- test/helper.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/devscripts/run_tests.py b/devscripts/run_tests.py index e39aa7af0..cf33d443d 100755 --- a/devscripts/run_tests.py +++ b/devscripts/run_tests.py @@ -51,7 +51,7 @@ def run_tests(*tests, pattern=None, ci=False, load_plugins=False): try: return subprocess.call(arguments, env={ **os.environ, - '_YT_DLP_TEST_DO_LOAD_PLUGINS': '1' if load_plugins else '', + 'YTDLP_NO_PLUGINS': '1' if os.environ.get('YTDLP_NO_PLUGINS') or not load_plugins else '', }) except FileNotFoundError: pass diff --git a/test/helper.py b/test/helper.py index e999993fb..3a73c191b 100644 --- a/test/helper.py +++ b/test/helper.py @@ -88,7 +88,7 @@ def report_warning(self, message, *args, **kwargs): def gettestcases(include_onlymatching=False): - if os.environ.get('_YT_DLP_TEST_DO_LOAD_PLUGINS'): + if not os.environ.get('YTDLP_NO_PLUGINS'): import yt_dlp.plugins as plugins plugins.load_all_plugins() for ie in yt_dlp.extractor.gen_extractors():