ValueError on compound assert with percent

Issue #615 on hold
Tom V
created an issue

Assertions like assert 1 % 1 or False or assert True and 1 % 1 fail with: ValueError: unsupported format character ')' (0x29) at index 7.

This behaviour is not seen with py.test --assert=reinterp or --assert=plain.

Example:

def test_high_odd():
    n = 20
    high = n > 10
    assert high and (n % 2 > 0)

def test_simple_percent_error():
    assert 1 % 1 and False

# no ValueError
def test_var_high_odd():
    n = 20
    high = n > 10
    odd = n % 2 > 0
    assert high and odd

$ py.test percent_error.py 
=== test session starts ===
platform linux2 -- Python 2.7.6 -- py-1.4.25 -- pytest-2.6.4.dev1
collected 3 items

percent_error.py FFF

=== FAILURES ===
___ test_high_odd ___

    def test_high_odd():
        n = 20
        high = n > 10
>       assert high and (n % 2 > 0)
E       ValueError: unsupported format character ')' (0x29) at index 17

percent_error.py:5: ValueError
___ test_simple_percent_error ___

    def test_simple_percent_error():
>       assert 1 % 1 and False
E       ValueError: unsupported format character ')' (0x29) at index 7

percent_error.py:8: ValueError
___ test_var_high_odd ___

    def test_var_high_odd():
        n = 20
        high = n > 10
        odd = n % 2 > 0
>       assert high and odd
E       assert (True and False)

percent_error.py:15: AssertionError
=== 3 failed in 0.01 seconds ===

Happy to have a go at writing a failing test in TestAssertionRewrite.

Comments (7)

  1. Log in to comment