3 ms·
It would be great if they could go into more detail on what they've improved over pyhamcrest (https://github.com/hamcrest/PyHamcrest https://github.com/hamcrest
by calpaterson 6y ago
It would be great if they could go into more detail on what they've improved over pyhamcrest (https://github.com/hamcrest/PyHamcrest https://github.com/hamcrest/PyHamcrest) which I do use on occasion when there is no other easy way to write a good matcher. That said though, pytest's assertion rewriting goes a long way towards making hamcrest-style assertions redundant. But not completely.
- BerislavLopac 6y agoDo you have an example of the "not completely" case?
- calpaterson 6y agoIt's still not that easy to assert on some of the keys in a dict but not others, especially if you only want to assert on some of the keys nested inside that key, and so on. There are a few other cases that perhaps don't come to mind straight away, many to do with having complex rules for what is allowed to be in another thing.
- BerislavLopac 6y agoI'm not sure what do you mean exactly... If it's something like: assert foo["bar"] == 123 assert foo["baz"]["bam"]["boo"] = "abc" I don't see how is that made easier (and less ambiguous) in hamcrest-style assertions...
- calpaterson 6y agoThe case is more like when you want to assert against some of the contents of a dictionary but not all (say 60% of a 30 key dict), and not all those assertions are based on == (and it's a multilevel nested dict). There's no particurly terse why to write an example I'm afraid.
- mwilliamson 6y ago(I'm the author of precisely) Better error messages was the motivation: PyHamcrest tends to put everything onto one line, which makes it hard to discern structure. In contrast, precisely tries to produce an error message that uses line breaks and indentation to match the structure of the matcher, hopefully making it clear exactly which part of the matcher has failed.
- neolog 6y agoThat sounds like a feature PyHamcrest could add. Did you try adding it there?
- olau 6y agopytest assertion rewrite in the standard Python library would be really, really nice. I don't think the standard lib gets enough love.