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

formatting should not matter in comparaison #125

Open
12rambau opened this issue Mar 15, 2023 · 4 comments
Open

formatting should not matter in comparaison #125

12rambau opened this issue Mar 15, 2023 · 4 comments

Comments

@12rambau
Copy link
Contributor

I started using pytest-regressions in sphinx repository where we mostly build html content. this time I'm usinge the data_regression feature and I really like it.

THe problem is that my libs are always parsed by a prettier pre-commit hook which does the following for yaml files:

  • use double quotes
  • indent with 2 spaces

The consequence is that comparaison performed by the lib is failing because the 2 files are effectively different. I think that's the same provblem as #50, we want to compare data and in the background pytest-regressions is comparaing files (which implies that formatting and order are taken into account when they shouldn't).

Would it be possible to change paradigm and instead of transforming data to a file and then compare, read the source first as a dict and compare them with the data ?

Happy to help building up a PR if someone that knows the lib better confirms it could be possible

@nicoddemus
Copy link
Member

THe problem is that my libs are always parsed by a prettier pre-commit hook which does the following for yaml files

You mean the hook is formatting the generated files? In that case I suggest using a different extension, or configure pre-commit to not format the generated files somehow.

@12rambau
Copy link
Contributor Author

12rambau commented Mar 16, 2023

this is what I did, so everything works smoothly now but I was thinking that being format dependant (order, indentation, etc...) should not be the case as I don't formally generate a yaml file but just a dict. I slept on it and I was thinking maybe this lib could simply format the generated and saved yaml before comparing (reorder keys + using a consistent formatting).

If you think it's useless extra-burden, you can close this issue (I'll write down the workaround for prettier pre-commit)

@nicoddemus
Copy link
Member

It is a good point, to actually compare the data instead of diff-ing the files: diffing the files could be done later, if the comparison fails (just to better visualize the differences).

@CarliJoy
Copy link

CarliJoy commented Jun 6, 2023

I also would argue that comparing the dicts directly instead of the files is the way to go.
To do this one could look into pytest-clarity or pytest-icdiff as described in #122

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