Within a unit test, I'm using monkeypatch
in order to change entries in a dict
.
from hypothesis import given, strategies
test_dict = {"first": "text1", "second": "text2"}
given(val=strategies.text())
def test_monkeypath(monkeypatch, val):
monkeypatch.setitem(test_dict, "second", val)
assert isinstance(test_dict["second"], str)
The test passes, but I get a warning when executing the following test code with pytest
.
=================================================================================================================== warnings summary ====================================================================================================================
.PyCharm2019.2/config/scratches/hypothesis_monkeypatch.py::test_monkeypath
c:\users\d292498\appdata\local\conda\conda\envs\pybt\lib\site-packages\hypothesis\extra\pytestplugin.py:172: HypothesisDeprecationWarning: .PyCharm2019.2/config/scratches/hypothesis_monkeypatch.py::test_monkeypath uses the 'monkeypatch' fixture, wh
ich is reset between function calls but not between test cases generated by `@given(...)`. You can change it to a module- or session-scoped fixture if it is safe to reuse; if not we recommend using a context manager inside your test function. See h
ttps://docs.pytest.org/en/latest/fixture.html#sharing-test-data for details on fixture scope.
note_deprecation(
-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================================================================================= 1 passed, 1 warning in 0.30s ==============================================================================================================
Does this mean that the value of the dict will only be changed once, no matter how many test cases will be generated by hypothesis
?
I am not sure how to use a context manager in this case. Can somebody please point me in the right direction?