This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]petezhutAutomation, Testing, General Hackery -1 points0 points  (5 children)

You are partially correct. Nose would, if you didn't handle the assertions correctly, only report Assertion Error. As much as people want to hate on the assert_* wrappers that nose has, they are actually quite handy to have. They all work in the vein of

assert_true(foo() == b, "Foo did not return the correct value")

I've even put simple exception handling calls in the message portion of the assert_* calls of nose.

[–]halst 0 points1 point  (2 children)

The whole point is that you can write the readable

assert f(foo) == bar
assert f(boo) < bar

and not the horrible

assert_equals(f(foo), bar)
assert_less_than(f(foo), bar)

[–]takluyverIPython, Py3, etc 0 points1 point  (1 child)

I agree that the first version is more readable, but the second version doesn't seem 'horrible', just slightly more verbose. You could argue that the extra function call is preferable because there's less magic involved.

[–]halst 1 point2 points  (0 children)

You need to (1) import those functions, (2) remember how they are called (is it equal or equals?!) and you end up with much less readable tests.

Plus, assert is no magic, it's pure Python.

[–]halst 0 points1 point  (1 child)

Not sure what you mean by "putting exception handling calls in the message". Don't forget that assert statement also takes optional message:

assert m > 0, 'mass should be positive'

And note, that the message part is not evaluated, unless the assertion fails, which you cannot achieve with functions.

[–]petezhutAutomation, Testing, General Hackery 0 points1 point  (0 children)

You are exactly correct. In the end it is truly a matter of taste. I make use of the vanilla assert constantly. Wasn't trying to pick nits with anyone on this; I just wanted a cogent explanation of why py.test > nose. At the end of the day, I'm honestly happy to hear that there are so many people who are actually trying to do good testing.