Skip to content

Commit

Permalink
Better error message when traversal fails
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw296 committed Nov 29, 2023
1 parent 7fcbc3d commit 920ba0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions testfixtures/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def resolve(dotted_name: str, container: Optional[Any] = None) -> Resolved:
else:
found = getattr(found, name)
setter = getattr
if found is not_there:
break
return Resolved(container, setter, name, found)


Expand Down
5 changes: 5 additions & 0 deletions testfixtures/tests/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ def test_constant(self):
from .sample3 import SOME_CONSTANT as sample3_some_constant
compare(sample3_some_constant, expected=43)

def test_relative_nested_but_not_present(self):
nested = {'b': [1, 2, 3]}
with Replacer() as r:
with ShouldRaise(AttributeError("Original 'a' not found")):
r(container=nested, target='.a.1', replacement=42)

class TestEnviron:

Expand Down

0 comments on commit 920ba0a

Please sign in to comment.