Skip to content

Commit

Permalink
Raise AttributeError in errors module
Browse files Browse the repository at this point in the history
Previously, `hypothesis.errors` would return `None` when any arbitrary
attribute was accessed.
  • Loading branch information
pganssle committed Apr 30, 2023
1 parent b926247 commit 2f15be1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,4 @@
RELEASE_TYPE: minor

:mod:`~hypothesis.errors` will now raise :py:exc:`AttributeError` when attempting
to access an undefined attribute, rather than returning :py:obj:`None`.
2 changes: 2 additions & 0 deletions hypothesis-python/src/hypothesis/errors.py
Expand Up @@ -132,6 +132,8 @@ def __getattr__(name):
)
return BaseExceptionGroup

raise AttributeError(f"Module 'hypothesis.errors' has no attribute {name}")


class DeadlineExceeded(_Trimmable):
"""Raised when an individual test body has taken too long to run."""
Expand Down
5 changes: 5 additions & 0 deletions hypothesis-python/tests/cover/test_escalation.py
Expand Up @@ -72,5 +72,10 @@ def test_multiplefailures_deprecation():
assert exc is BaseExceptionGroup


def test_errors_attribute_error():
with pytest.raises(AttributeError):
errors.ThisIsNotARealAttributeDontCreateSomethingWithThisName


def test_handles_null_traceback():
esc.get_interesting_origin(Exception())

0 comments on commit 2f15be1

Please sign in to comment.