This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rbcollins
Recipients ChrisBarker, ezio.melotti, mark.dickinson, michael.foord, r.david.murray, rbcollins
Date 2016-06-03.23:30:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464996613.86.0.0763019971603.issue27198@psf.upfronthosting.co.za>
In-reply-to
Content
Future direction: hamcrest style matchers. You can read more about them in the context of unittest https://rbtcollins.wordpress.com/2010/05/10/maintainable-pyunit-test-suites/ and http://testtools.readthedocs.io/en/latest/for-test-authors.html#matchers - sorry about the formatting in the blog post, wordpress changed theme details some time after I wrote the post and it now renders horribly :(.

w.r.t. error messages, a regular function that raises AssertionError with a nice message will be precisely as usable.

def assert_math_isclose(first, second, rel_tol=1e-09, abs_tol=0.0, msg=None):
    if math.isclose(first, second, rel_tol=rel_tol, abs_tol=abs_tol):
        return
    standardMsg = ('%s != %s with relative tolerance of %.3g'
                   ' and absolute tolerance of %.3g' % (safe_repr(first),
                                                        safe_repr(second),
                                                        rel_tol,
                                                        abs_tol))
    if msg:
        raise AssertionError("{} : {}".format(standardMsg, msg))
    else:
        raise AssertionError(standardMsg)

The reason I'm pushing back on adding methods to TestCase is that every one we add collides with some number of subclasses out in the wild: the TestCase class has multiple distinct APIs in the same namespace - and thats very poor for maintaining compatibility.

Long term I want to have entirely separate interfaces for these things, but thats even more radical an overhaul than adding matchers as a stock facility, and I don't currently have a planned timeline for starting on that.

All of that said, I see that this isn't the same as assertAlmostEqual in mathematical terms - but in /user/ terms I think it is. So why can't we make assertAlmostEqual be this? Just add the extra parameter needed with a default value and change the implementation?
History
Date User Action Args
2016-06-03 23:30:13rbcollinssetrecipients: + rbcollins, mark.dickinson, ezio.melotti, r.david.murray, michael.foord, ChrisBarker
2016-06-03 23:30:13rbcollinssetmessageid: <1464996613.86.0.0763019971603.issue27198@psf.upfronthosting.co.za>
2016-06-03 23:30:13rbcollinslinkissue27198 messages
2016-06-03 23:30:13rbcollinscreate