diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-02-02 12:59:30 +0300 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-02-09 19:17:14 +0300 |
commit | d299e8854d8ffcea39aa93e6c807bdb93a0821ae (patch) | |
tree | 0fc7c5a9ceb08ce19367c0fed8a9d589a650df53 | |
parent | 2294e1cc7147afff7407d26b0ab809b5dab8f8b8 (diff) | |
download | ydb-d299e8854d8ffcea39aa93e6c807bdb93a0821ae.tar.gz |
Intermediate changes
6 files changed, 29 insertions, 18 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA index d32ce6bcf3..6bcb5326b8 100644 --- a/contrib/python/hypothesis/py3/.dist-info/METADATA +++ b/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 diff --git a/contrib/python/hypothesis/py3/_hypothesis_globals.py b/contrib/python/hypothesis/py3/_hypothesis_globals.py index e97e091879..1f3eb6fd6d 100644 --- a/contrib/python/hypothesis/py3/_hypothesis_globals.py +++ b/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 diff --git a/contrib/python/hypothesis/py3/_hypothesis_pytestplugin.py b/contrib/python/hypothesis/py3/_hypothesis_pytestplugin.py index 944304ccdb..e82b528bb5 100644 --- a/contrib/python/hypothesis/py3/_hypothesis_pytestplugin.py +++ b/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 diff --git a/contrib/python/hypothesis/py3/hypothesis/configuration.py b/contrib/python/hypothesis/py3/hypothesis/configuration.py index 2586c729f7..b7bc8879ce 100644 --- a/contrib/python/hypothesis/py3/hypothesis/configuration.py +++ b/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, ) diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py index 74dd286d5c..e617676c40 100644 --- a/contrib/python/hypothesis/py3/hypothesis/version.py +++ b/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__)) diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make index f868902be4..c97103a0b1 100644 --- a/contrib/python/hypothesis/py3/ya.make +++ b/contrib/python/hypothesis/py3/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(6.96.0) +VERSION(6.96.1) LICENSE(MPL-2.0) |