Browse Source

Intermediate changes

robot-piglet 1 year ago
parent
commit
8319f36af9

+ 1 - 1
contrib/python/hypothesis/py3/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: hypothesis
-Version: 6.96.0
+Version: 6.96.1
 Summary: A library for property-based testing
 Home-page: https://hypothesis.works
 Author: David R. MacIver and Zac Hatfield-Dodds

+ 2 - 2
contrib/python/hypothesis/py3/_hypothesis_globals.py

@@ -16,9 +16,9 @@ depending on either. This file should have no imports outside of stdlib.
 import os
 
 in_initialization = 1
-"""If nonzero, indicates that hypothesis is still initializing (importing or loading
+"""If >0, indicates that hypothesis is still initializing (importing or loading
 the test environment). `import hypothesis` will cause this number to be decremented,
-and the pytest plugin increments at load time, then decrements it just before the test
+and the pytest plugin increments at load time, then decrements it just before each test
 session starts. However, this leads to a hole in coverage if another pytest plugin
 imports hypothesis before our plugin is loaded. HYPOTHESIS_EXTEND_INITIALIZATION may
 be set to pre-increment the value on behalf of _hypothesis_pytestplugin, plugging the

+ 1 - 7
contrib/python/hypothesis/py3/_hypothesis_pytestplugin.py

@@ -101,7 +101,6 @@ else:
     # need balanced increment/decrement in configure/sessionstart to support nested
     # pytest (e.g. runpytest_inprocess), so this early increment in effect replaces
     # the first one in pytest_configure.
-    _configured = False
     if not os.environ.get("HYPOTHESIS_EXTEND_INITIALIZATION"):
         _hypothesis_globals.in_initialization += 1
         if "hypothesis" in sys.modules:
@@ -163,12 +162,6 @@ else:
         return f"hypothesis profile {settings._current_profile!r}{settings_str}"
 
     def pytest_configure(config):
-        global _configured
-        # skip first increment because we pre-incremented at import time
-        if _configured:
-            _hypothesis_globals.in_initialization += 1
-        _configured = True
-
         config.addinivalue_line("markers", "hypothesis: Tests which use hypothesis.")
         if not _any_hypothesis_option(config):
             return
@@ -430,6 +423,7 @@ else:
                 item.add_marker("hypothesis")
 
     def pytest_sessionstart(session):
+        # Note: may be called multiple times, so we can go negative
         _hypothesis_globals.in_initialization -= 1
 
     # Monkeypatch some internals to prevent applying @pytest.fixture() to a

+ 23 - 6
contrib/python/hypothesis/py3/hypothesis/configuration.py

@@ -9,6 +9,7 @@
 # obtain one at https://mozilla.org/MPL/2.0/.
 
 import os
+import sys
 import warnings
 from pathlib import Path
 
@@ -45,7 +46,7 @@ _first_postinit_what = None
 
 
 def check_sideeffect_during_initialization(
-    what: str, *fmt_args: object, extra: str = ""
+    what: str, *fmt_args: object, is_restart: bool = False
 ) -> None:
     """Called from locations that should not be executed during initialization, for example
     touching disk or materializing lazy/deferred strategies from plugins. If initialization
@@ -60,13 +61,29 @@ def check_sideeffect_during_initialization(
     # notice_initialization_restarted() to be called if in_initialization changes away from zero.
     if _first_postinit_what is not None:
         return
-    elif _hypothesis_globals.in_initialization:
+    elif _hypothesis_globals.in_initialization > 0:
+        msg = what.format(*fmt_args)
+        if is_restart:
+            when = "between importing hypothesis and loading the hypothesis plugin"
+        elif "_hypothesis_pytestplugin" in sys.modules or os.getenv(
+            "HYPOTHESIS_EXTEND_INITIALIZATION"
+        ):
+            when = "during pytest plugin or conftest initialization"
+        else:  # pragma: no cover
+            # This can be triggered by Hypothesis plugins, but is really annoying
+            # to test automatically - drop st.text().example() in hypothesis.run()
+            # to manually confirm that we get the warning.
+            when = "at import time"
         # Note: -Werror is insufficient under pytest, as doesn't take effect until
         # test session start.
-        msg = what.format(*fmt_args)
+        text = (
+            f"Slow code in plugin: avoid {msg} {when}!  Set PYTHONWARNINGS=error "
+            "to get a traceback and show which plugin is responsible."
+        )
+        if is_restart:
+            text += " Additionally, set HYPOTHESIS_EXTEND_INITIALIZATION=1 to pinpoint the exact location."
         warnings.warn(
-            f"Slow code in plugin: avoid {msg} at import time!  Set PYTHONWARNINGS=error "
-            "to get a traceback and show which plugin is responsible." + extra,
+            text,
             HypothesisSideeffectWarning,
             stacklevel=3,
         )
@@ -87,5 +104,5 @@ def notice_initialization_restarted(*, warn: bool = True) -> None:
             check_sideeffect_during_initialization(
                 what,
                 *fmt_args,
-                extra=" Additionally, set HYPOTHESIS_EXTEND_INITIALIZATION=1 to pinpoint the exact location.",
+                is_restart=True,
             )

+ 1 - 1
contrib/python/hypothesis/py3/hypothesis/version.py

@@ -8,5 +8,5 @@
 # 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/.
 
-__version_info__ = (6, 96, 0)
+__version_info__ = (6, 96, 1)
 __version__ = ".".join(map(str, __version_info__))

+ 1 - 1
contrib/python/hypothesis/py3/ya.make

@@ -2,7 +2,7 @@
 
 PY3_LIBRARY()
 
-VERSION(6.96.0)
+VERSION(6.96.1)
 
 LICENSE(MPL-2.0)