From eee8dfed7cd1dc4eb1a70d91d97ffd1ede34b517 Mon Sep 17 00:00:00 2001 From: Joachim B Haga Date: Thu, 13 Jul 2023 16:25:48 +0200 Subject: [PATCH] Env var to skip loading of entrypoints. --- hypothesis-python/RELEASE.rst | 5 +++++ hypothesis-python/src/hypothesis/entry_points.py | 10 ++++++---- hypothesis-python/tests/cover/test_lazy_import.py | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 hypothesis-python/RELEASE.rst diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..7eb9221373 --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,5 @@ +RELEASE_TYPE: patch + +Read environment variable HYPOTHESIS_NO_ENTRYPOINTS to +optionally skip loading of third-party plugin entrypoints. + diff --git a/hypothesis-python/src/hypothesis/entry_points.py b/hypothesis-python/src/hypothesis/entry_points.py index 6a57258067..ce7661ab14 100644 --- a/hypothesis-python/src/hypothesis/entry_points.py +++ b/hypothesis-python/src/hypothesis/entry_points.py @@ -16,6 +16,7 @@ """ import importlib.metadata +import os def get_entry_points(): @@ -29,7 +30,8 @@ def get_entry_points(): def run(): - for entry in get_entry_points(): # pragma: no cover - hook = entry.load() - if callable(hook): - hook() + if not os.environ.get("HYPOTHESIS_NO_ENTRYPOINTS"): + for entry in get_entry_points(): # pragma: no cover + hook = entry.load() + if callable(hook): + hook() diff --git a/hypothesis-python/tests/cover/test_lazy_import.py b/hypothesis-python/tests/cover/test_lazy_import.py index c1fb992670..b95d1bcb10 100644 --- a/hypothesis-python/tests/cover/test_lazy_import.py +++ b/hypothesis-python/tests/cover/test_lazy_import.py @@ -8,6 +8,7 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at https://mozilla.org/MPL/2.0/. +import os import subprocess import sys @@ -44,4 +45,7 @@ def test_hypothesis_does_not_import_test_runners(tmp_path): # See https://github.com/HypothesisWorks/hypothesis/pull/2204 fname = tmp_path / "test.py" fname.write_text(SHOULD_NOT_IMPORT_TEST_RUNNERS, encoding="utf-8") - subprocess.check_call([sys.executable, str(fname)]) + subprocess.check_call( + [sys.executable, str(fname)], + env=os.environ | {"HYPOTHESIS_NO_ENTRYPOINTS": "1"}, + )