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

Ignoring parameters when comparing snapshot to serialized object #861

Open
irahorecka opened this issue Mar 11, 2024 · 1 comment
Open

Comments

@irahorecka
Copy link

irahorecka commented Mar 11, 2024

How to ignore parameters when comparing snapshot to serialized object?

My collaborators and I naturally run tests on different machines, therefore, classes / functions that have file path parameters will have different values when taking snapshots. How do I deliberately ignore this parameter (e.g., filename) altogether? I would like one centralized snapshot that can be compared without the comparison of file paths, if possible.

I've tried using snapshot(exclude=props("filename")) (filename is the parameter to ignore) to no avail.

Screen Shot 2024-03-11 at 2 12 18 PM

@yedpodtrzitko
Copy link

it looks like filename is not a property in the root of the snapshot, which is why it's ignored. You have to specify the path to the property.

Or, instead of excluding the property, you can use matcher to check just the value type instead of checking the actual value:

snapshot(
    matcher=path_type({
        "path.to.filename.property": (str,), # the value is expected to be `str`
    })
)

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

2 participants