From 306c7a5f6f7562d0ab57c30511a8bec9429a7aa6 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Mon, 10 Jan 2022 13:04:57 -0500 Subject: [PATCH] Simplify diffs using 'expect.anything' --- CHANGELOG.md | 4 ++++ docs/requirements.txt | 2 ++ expecter/__init__.py | 3 +++ pyproject.toml | 2 +- tests/test_diff.py | 8 ++++++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f80cb..6d69f21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)`. diff --git a/docs/requirements.txt b/docs/requirements.txt index 93c147d..ae0d14b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -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" diff --git a/expecter/__init__.py b/expecter/__init__.py index 06c4ede..a4f9cd3 100644 --- a/expecter/__init__.py +++ b/expecter/__init__.py @@ -27,6 +27,9 @@ class Anything: """Placeholder value to ignore uninteresting response data.""" + def __repr__(self): + return '' + def __eq__(self, other): return True diff --git a/pyproject.toml b/pyproject.toml index ef038c7..b905d68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pytest-expecter" -version = "2.2" +version = "2.3" description = "Better testing with expecter and pytest." license = "BSD" diff --git a/tests/test_diff.py b/tests/test_diff.py index 9435fa2..e0e0a95 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -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': " in fail_msg(_fails), fail_msg(_fails)