-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we need snapshot()
?
#41
Comments
hi, thank you for the kind words 🙂 Why notI don't think that inline-snapshot can work without magic_value=snapshot()
def test_something1():
assert something1() == magic_value
def test_something2():
assert something2() == magic_value There is also another thing which I probably not described in the docs completely. The snapshot function has basically noop semantics, which means that you can do something like this: try:
from inline_snapshot import snapshot
except ImportError:
def snapshot(value):
return value I don't know if this help with the "forcing every collaborator to install it" part. How maybeThe only option I currently see how this could maybe be done is with a complete ast rewrite at import time. You could transform every assert like follow: assert something()==5,"message"
# to
__soft_eq_assert(something(),5,"message",some_line_and_col_information) pytest assert rewriting would not work, but this might be acceptable. The assert failure could then be reported after the test is completely run. I do something similar here: inline-snapshot/inline_snapshot/pytest_plugin.py Lines 85 to 94 in 1b4b80d
|
That is a good approach! It not perfectly elegant (there are still interesting re the ast rewrite. That would be quite intrusive, but I does seem like it should work... Another possible approach might be: max-sixty/pytest-accept#57, let me know if you have any thoughts... |
As the author noted, this solution might become a problem if the internal pytest api change. Rewriting the whole module (which would implicit disable the pytest assert rewrite) might be a better option in this case, because you don't have to touch any pytest internals. Disabling the pytest assert rewriting might not be a problem if you do it only when you run pytest with the --accept option. |
I have maybe an idea how this can be integrated into inline-snapshot but this would require that we can use inline-snapshot and pytest assert rewriting together (assert rewriting is currently disabled when you change snapshots) It might be possible then to hook into |
Hi — I'm the creator of pytest-accept, a similar library, but limited to doctests.
Great work on this! Excited to see a well-made effort.
Something I tried to work into
pytest-accept
was being able to use it without forcing every collaborator to install it.Would it be feasible to not require
foo = snapshot("bar")
, and instead just replace any values that are incorrect, sofoo = ""
is changed tofoo = "bar"
?The text was updated successfully, but these errors were encountered: