Skip to content
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

insert_assert #117

Open
samuelcolvin opened this issue Nov 25, 2022 · 5 comments
Open

insert_assert #117

samuelcolvin opened this issue Nov 25, 2022 · 5 comments

Comments

@samuelcolvin
Copy link
Owner

samuelcolvin commented Nov 25, 2022

we should move samuelcolvin/dirty-equals#51 to this package.

Function should be debug.insert_assert, but we still need the library to become a pytest plugin so tests with insert_assert can fail.

@zmievsa
Copy link

zmievsa commented Jun 5, 2023

Hey, I tried insert_assert and loved it! I would like and could implement a nice feature but would be interested whether you'd like to merge it:

Add a version (or a configuration) of insert_assert that captures values from locals(), compares their values to parts of the object to be asserted (i.e. if it's a dict, then we'll check the keys and values recursively), and inserts variable names instead of raw values. It is very useful when the value being checked is dynamic such as a date or a uuid.

Essentially using aliases in place of literals whenever possible.

@samuelcolvin
Copy link
Owner Author

I think this is often an anti pattern in testing as it can make the test less declarative, I'd rather avoid it.

If you want to implement it, happy to review a PR, but it should be behind a flag.

@alexmojaki
Copy link
Contributor

Is this issue still open as a reminder to add insert_assert to the documentation?

@zmievsa
Copy link

zmievsa commented Sep 10, 2023

I guess so.

@alexmojaki
Copy link
Contributor

@zmievsa I'm hoping to add something like what you're describing to a similar library here: 15r10nk/inline-snapshot#53

It won't automatically generate code using variables, but if it sees variables or other expressions inside an existing snapshot, it'll try to preserve them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants