[py-dev] Assert repr of attributes
holger krekel
holger at merlinux.eu
Wed Oct 6 10:55:41 CEST 2010
Hi Floris,
On Tue, Oct 05, 2010 at 21:22 +0100, Floris Bruynooghe wrote:
> Hello
>
> Another possible improvement to the assert repr of py.test (IMHO) is
> how attributes are represented. One thing I often find myself doing
> is code like this:
>
> def test_foo():
> i = SomeClass()
> print i.attribute_name
> assert i.attribute_name == "some_value"
Yes, this annoyed me as well a couple of times :)
> The printing of the attribute name is simply to work around the
> slightly annoying (IMHO) default representation of attributes, it
> could have been a one-liner test otherwise (assuming no side-effects
> in the call). While it is really nice to see where it came from, just
> knowing the value is often very useful (e.g. when it could be None or
> a meaning value).
>
> So the attached patch addresses this. It's just a one-line change
> really, and I think the output is a lot nicer. Personally I can't see
> what could be wrong with this approach so don't think moving this to a
> plugin or making it otherwise optional is needed.
right. There was something that was problematic IIRC but i am not sure
what it was. And it surely is useful. So let's apply it :)
Can you create a bundle for this changeset
or let me pull this change from your repo?
> I hope this can be a useful addition.
sure!
holger
More information about the Pytest-dev
mailing list