-
-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I find the diff output that pytest-insta produces confusing. On further investigation, it seems as though it's backwards w.r.t. pytest's conventions.
An example:
I setup the following test and get a snapshot:
def test_hello_world(snapshot):
assert snapshot() == "hello world"The snapshot file contains:
hello world
Now I change my test:
def test_hello_world(snapshot):
assert snapshot() == "hello bob"I expect to see the following diff:
E - hello world
E + hello bob
Instead, I see the following:
E - hello bob
E + hello world
There was a long discussion in the pytest repo about which direction the +/- symbols should go in a diff. The summary is that the convention is that assertions should be written like:
assert computed == expected
And correspondingly, the diff of assert [1, 4, 3] == [1, 2, 3] should be (from this comment):
# "2" is expected but the result list contains "4" instead.
E [
E 1,
E - 2,
E + 4,
E 3,
E ]
Similarly, for the following test:
def test_array_eq():
assert "hello bob" == "hello world"I get:
> assert "hello bob" == "hello world"
E AssertionError: assert 'hello bob' == 'hello world'
E
E - hello world
E + hello bob
Because pytest-insta is in control of passing the text to be formatted to pytest, I think that the following diff should be sufficient to fix this:
diff --git a/pytest_insta/review.py b/pytest_insta/review.py
index fdd9804..831dc7c 100644
--- a/pytest_insta/review.py
+++ b/pytest_insta/review.py
@@ -57,10 +57,10 @@ class ReviewTool:
yield test, snapshot, original
def display_assertion(self, old: Any, new: Any):
- self.tr.write_line("\n> assert old == new")
+ self.tr.write_line("\n> assert new == old")
lines, *_ = self.config.hook.pytest_assertrepr_compare(
- config=self.config, op="==", left=old, right=new
+ config=self.config, op="==", left=new, right=old
)
explanation = "assert " + "\n".join(" " + line for line in lines).strip()