samuelcolvin/python-devtools

`insert_assert`

samuelcolvin opened this issue · 5 comments

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.

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.

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.

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

I guess so.

@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.