Skip to content

Commit

Permalink
Merge pull request #3698 from jobh/entrypoint-skipping
Browse files Browse the repository at this point in the history
Env var to skip loading of entrypoints.
  • Loading branch information
Zac-HD committed Jul 15, 2023
2 parents e763816 + c0d36fd commit b2b58bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
10 changes: 10 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RELEASE_TYPE: patch

If the :envvar:`HYPOTHESIS_NO_PLUGINS` environment variable is set, we'll avoid
:ref:`loading plugins <entry-points>` such as `the old Pydantic integration
<https://docs.pydantic.dev/latest/integrations/hypothesis/>`__ or
`HypoFuzz' CLI options <https://hypofuzz.com/docs/quickstart.html#running-hypothesis-fuzz>`__.

This is probably only useful for our own self-tests, but documented in case it might
help narrow down any particularly weird bugs in complex environments.

6 changes: 6 additions & 0 deletions hypothesis-python/docs/strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ and then tell ``setuptools`` that this is your ``"hypothesis"`` entry point:
And that's all it takes!

.. envvar:: HYPOTHESIS_NO_PLUGINS

If set, disables automatic loading of all hypothesis plugins. This is probably only
useful for our own self-tests, but documented in case it might help narrow down
any particularly weird bugs in complex environments.


Interaction with :pypi:`pytest-cov`
-----------------------------------
Expand Down
10 changes: 6 additions & 4 deletions hypothesis-python/src/hypothesis/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import importlib.metadata
import os


def get_entry_points():
Expand All @@ -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_PLUGINS"):
for entry in get_entry_points(): # pragma: no cover
hook = entry.load()
if callable(hook):
hook()
6 changes: 5 additions & 1 deletion hypothesis-python/tests/cover/test_lazy_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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_PLUGINS": "1"}},
)

0 comments on commit b2b58bd

Please sign in to comment.