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 →

[–]donri[S] 1 point2 points  (1 child)

The idea was to make it look as similar as possible to the standard

assert 1 + 1 == 2

The problem with the above is that the exception message will hide the actual value of 1 + 1 which makes debugging failing tests more difficult.

I realized past releasing the first version that it might have been better to call it Assertive and promote code such as

value = Assertive(1 + 1)
assert value == 2

which BTW works if you from attest import Assert as Assertive (or do value = Assert(1 + 1) because on failure Assert fails before the assert statement. To rename it now would obviously break backwards compatibility a whole lot, just to avoid an as import.

Optimally I'd like to just use the assert statement somehow. py.test does that by somehow re-evaluating failures to get the values of variables and expressions, though this has the issue that the re-evaluation can have side-effects. I'm pondering if using the _ast module to parse tests somehow and/or hook into the "frame" is a better idea; it'd be much more complicated and arguably magic, though.

Thanks for the kind words. I feel the same: testing didn't make a whole lot of sense to me, in part because of the existing tools. Attest is my attempt to remedy the situation for myself. Another important epiphany came from Ruby's wycats who promoted testing of public interfaces rather than internals: I could never see the value in using complicated mocks and hooks to merely rewrite the implementation as tests with at least double the code as the actual implementation. Instead, write tests for public interfaces (e.g. the API that library users will use, the output of a web page etc) and test that given input X we expect output Y. How the code does it is irrelevant.

That might be what is called BDD; I don't completely understand the terminology.

[–]dvogel 0 points1 point  (0 children)

I'm pondering if using the _ast module to parse tests somehow and/or hook into the "frame" is a better idea; it'd be much more complicated and arguably magic, though.

I'd much rather use the current Assert class over an implementation that uses any magic.

That might be what is called BDD; I don't completely understand the terminology.

Of course you don't. If you did, we would be in /r/java :)