Skip to content

Commit

Permalink
Merge pull request #19 from jacebrowning/simplify-diffs
Browse files Browse the repository at this point in the history
Simplify diffs using 'expect.anything'
  • Loading branch information
jacebrowning authored Jan 10, 2022
2 parents bb92389 + 306c7a5 commit 44401b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.3 (2022-01-20)

- Updated the representation of `expect.anything` to simplify diffs.

# 2.2 (2020-07-08)

- Added support for matching non-identity via `expect(actual).is_not(expected)`.
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mkdocs==1.2.3; python_version >= "3.6"
pygments==2.11.2; python_version >= "3.5"
mkdocs==1.2.3; python_version >= "3.6"
pygments==2.11.2; python_version >= "3.5"
3 changes: 3 additions & 0 deletions expecter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
class Anything:
"""Placeholder value to ignore uninteresting response data."""

def __repr__(self):
return '<anything>'

def __eq__(self, other):
return True

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "pytest-expecter"
version = "2.2"
version = "2.3"
description = "Better testing with expecter and pytest."

license = "BSD"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ def _fails():
"-[{'a': 1, 'b': 22, 'c': 3, 'd': 4, 'f': 6, 'g': 7}]\n"
"+[{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6}]"
), fail_msg(_fails)

def it_supports_ignoring_values_with_anything():
def _fails():
expect({'foo': 2, 'bar': None}) == {'foo': 1, 'bar': expect.anything}

with pytest.raises(AssertionError):
_fails()
assert "'bar': <anything>" in fail_msg(_fails), fail_msg(_fails)

0 comments on commit 44401b2

Please sign in to comment.