make hypothesis optional for testing (#2343)

* make hypothesis optional for testing

* fix coveragin in "_hypothesis_plugin.py"

* uncomment ci checks
This commit is contained in:
Samuel Colvin
2021-02-12 10:46:34 +00:00
committed by GitHub
parent a1ac464371
commit 1ee9737cf5
3 changed files with 19 additions and 4 deletions
+2 -2
View File
@@ -59,7 +59,7 @@ else:
try:
email_validator.validate_email(s, check_deliverability=False)
return True
except email_validator.EmailNotValidError:
except email_validator.EmailNotValidError: # pragma: no cover
return False
# Note that these strategies deliberately stay away from any tricky Unicode
@@ -217,7 +217,7 @@ def resolves(
def resolve_json(cls): # type: ignore[no-untyped-def]
try:
inner = st.none() if cls.inner_type is None else st.from_type(cls.inner_type)
except Exception:
except Exception: # pragma: no cover
finite = st.floats(allow_infinity=False, allow_nan=False)
inner = st.recursive(
base=st.one_of(st.none(), st.booleans(), st.integers(), finite, st.text()),
+6 -1
View File
@@ -10,7 +10,12 @@ import pytest
from _pytest.assertion.rewrite import AssertionRewritingHook
# See https://hypothesis.readthedocs.io/en/latest/strategies.html#interaction-with-pytest-cov
pytest_plugins = ['hypothesis.extra.pytestplugin']
try:
import hypothesis # noqa
except ImportError:
pytest_plugins = []
else:
pytest_plugins = ['hypothesis.extra.pytestplugin']
def _extract_source_code_from_function(function):
+11 -1
View File
@@ -1,11 +1,21 @@
import typing
import pytest
from hypothesis import given, strategies as st
import pydantic
from pydantic.networks import import_email_validator
try:
from hypothesis import given, strategies as st
except ImportError:
def given(*args, **kwargs):
return lambda f: f
st = type('st', (), {'data': lambda: None})
pytestmark = pytest.mark.skipif(True, reason='"hypothesis" not installed')
def gen_models():
class MiscModel(pydantic.BaseModel):