diff --git a/brownie/exceptions.py b/brownie/exceptions.py index 1a14a888e..4baff9b85 100644 --- a/brownie/exceptions.py +++ b/brownie/exceptions.py @@ -135,3 +135,7 @@ class BrownieEnvironmentWarning(Warning): class InvalidArgumentWarning(BrownieEnvironmentWarning): pass + + +class BrownieTestWarning(Warning): + pass diff --git a/brownie/test/__init__.py b/brownie/test/__init__.py index ec9b11ab0..3f6f42f17 100644 --- a/brownie/test/__init__.py +++ b/brownie/test/__init__.py @@ -6,6 +6,7 @@ from hypothesis.errors import HypothesisDeprecationWarning from brownie import network +from brownie.exceptions import BrownieTestWarning from .stateful import state_machine # NOQA: F401 from .strategies import strategy # NOQA: F401 @@ -30,7 +31,7 @@ def isolation_wrapper(*args, **kwargs): # hypothesis.given must wrap the target test to correctly # impersonate the call signature for pytest - hy_given = hypothesis.given(*given_args, **given_kwargs) + hy_given = _hypothesis_given(*given_args, **given_kwargs) hy_wrapped = hy_given(test) if hasattr(hy_wrapped, "hypothesis"): @@ -38,3 +39,19 @@ def isolation_wrapper(*args, **kwargs): return hy_wrapped return outer_wrapper + + +def _given_warning_wrapper(*args, **kwargs): + warnings.warn( + "Directly importing `hypothesis.given` may result in improper isolation" + " between test runs. You should import `brownie.test.given` instead.", + BrownieTestWarning, + ) + return _hypothesis_given(*args, **kwargs) + + +def _apply_given_wrapper(): + hypothesis.given = _given_warning_wrapper + + +_hypothesis_given = hypothesis.given diff --git a/brownie/test/managers/base.py b/brownie/test/managers/base.py index d0f2e2ec7..cc7d19675 100644 --- a/brownie/test/managers/base.py +++ b/brownie/test/managers/base.py @@ -7,13 +7,14 @@ from brownie._config import CONFIG from brownie.project.scripts import _get_ast_hash -from brownie.test import coverage, output +from brownie.test import _apply_given_wrapper, coverage, output from .utils import convert_outcome class PytestBrownieBase: def __init__(self, config, project): + _apply_given_wrapper() self.config = config # required when brownie project is in a subfolder of another project