[py-dev] controlling assertions and difflib

Floris Bruynooghe flub at devork.be
Fri Oct 1 01:23:20 CEST 2010


Hello

On 29 September 2010 14:28, holger krekel <holger at merlinux.eu> wrote:
> On Wed, Sep 29, 2010 at 00:12 +0100, Floris Bruynooghe wrote:
>> ______________________________ test_hang_in_diff _______________________________
>> /tmp/sandbox/test_bugs.py:4: in test_hang_in_diff
>> >       assert x == y
>> E       assert '1\n1\n1\n1\n...n2\n2\n2\n2\n' == '1\n1\n1\n1\n...n2\n2\n2\n2\n'
>> E         Skipping 1990 identical leading characters in diff
>> E         Skipping 1991 identical trailing characters in diff
>> E           1
>> E           1
>> E           1
>> E           1
>> E           1
>> E         - abc2
>> E         + def2
>> E           2
>> E           2
>> E           2
>> E           2
>
>
> looks good to me!

I've committed a cleaned-up version of this now.


>> This whole issue made me wonder if it should be possible to disable
>> the pytest_assert_binrepr hook.
>
> We could do a general "--assertmode=(choice)" with e.g.:
>
>    0: (no) don't do any assert reinterp (like --no-assert now)
>    1: (basic) do basic reinterpreation
>    2: (advanced) do basic reinterpretation + customizing hooks
>
> and default to 2.

Sounds like a good idea.  Do you think there's place for a
advanced-no-builtin-plugin option in here, so that the builtin hook
will not run any code?  Otherwise a bug in the builtin customisation
hook would completely stop this from being useful.


> I think there is an elegant solution.  Instead of using "hook" in py/code/ we
> use a generic "customize" function that is to be called.  In
> pytest_assertion.py's pytest_configure we write that function
> such that it calls
>
>    pytest_assert_binrepr(config, ...)
>
> hope that makes sense. If in doubt leave it to me and just use py.test.config.

Do you mean something like the attached diff does?  In that case I'm
sort of tempted to remove the customise_assert() function I've added
there and just expose the DebugInterpreter so that you can modify the
attribute directly.  I also considered the
customise_assert(binrepr_hook, config) signature for this, not sure
which would be best.


Regards
Floris


-- 
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: config.diff
Type: text/x-patch
Size: 3108 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20101001/75ab3c7b/attachment.bin>


More information about the Pytest-dev mailing list