pytest-regressions icon indicating copy to clipboard operation
pytest-regressions copied to clipboard

formatting should not matter in comparaison

Open 12rambau opened this issue 2 years ago • 4 comments

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

12rambau avatar Mar 15 '23 21:03 12rambau

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.

nicoddemus avatar Mar 16 '23 10:03 nicoddemus

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)

12rambau avatar Mar 16 '23 12:03 12rambau

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

nicoddemus avatar Mar 16 '23 13:03 nicoddemus

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

CarliJoy avatar Jun 06 '23 09:06 CarliJoy