Replies: 1 comment 2 replies
-
I believe Full disclosure: I wrote it. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Does anyone know of a library of matcher objects or matcher functions that work nicely with pytest's
assert
statement? Or does anyone have any advice on how to write one?I'm talking about this sort of thing:
It wouldn't necessarily have to have this particular interface/API design. But the idea is that it provides a way to assert that
result
as an iterable (of any type) containing1
,2
and3
, in any order, but no other values, all in a single easy-to-write assertion.This particular example is a bit silly. But you can imagine a library with a collection of "matcher objects" like this for matching all sorts of different values (
AnyInstanceOf(SomeModel, with_attrs={"foo": 42, "bar": 23})
, etc), along with providing the user with the ability to write their own matchers.The aim is to enable writing complex test assertions more fluently.
PyHamcrest seems to be the leading implementation of this sort of thing in Python but that doesn't look particularly pytest-friendly. It has its own assertion methods like
assert_that(theBiscuit, equal_to(myBiscuit))
, rather than working with normalassert
's and comparisons.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions