Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing assert statement with Function call #1592

Closed
cksagni91 opened this issue Jun 7, 2016 · 4 comments
Closed

Printing assert statement with Function call #1592

cksagni91 opened this issue Jun 7, 2016 · 4 comments
Labels
type: bug problem that needs to be addressed

Comments

@cksagni91
Copy link

We are reading the exception output of Pytest using hooks.
The issue we are facing is that if function call in assert statement returns False, then it gives back the function statement itself

PyTest Version : 2.9.2
OS : Windows 8 - 64bit

Code :

def check_even(number):
    if number%2==0:
        return True
    else:
        return False

Testcases :

def test_check_even1():
    assert check_even(2) == False

def test_check_even2():
    assert check_even(3) == True

Output:

test_sol.py FF

================================== FAILURES ===================================
______________________________ test_check_even1 _______________________________

    def test_check_even1():
>       assert check_even(2) == False
E       assert True == False
E        +  where True = check_even(2)

test_sol.py:5: AssertionError
______________________________ test_check_even2 _______________________________

    def test_check_even2():
>       assert check_even(3) == True
E       assert check_even(3) == True

test_sol.py:8: AssertionError
========================== 2 failed in 0.08 seconds ===========================

As it can be seen, for the testcase test_check_even2, the error report is returned with
function_call == expected output [check_even(3) == True] , rather than
return_value_of_function == expected_output [ False == True ]

This issue occurs only if the function returns FALSE.

@nicoddemus nicoddemus added the type: bug problem that needs to be addressed label Jun 7, 2016
@nicoddemus
Copy link
Member

Thanks for the report!

@sallner
Copy link
Member

sallner commented Jun 27, 2016

Hi @cksagni91,

I think the main idea was to return assert check_even(3) to show the 'False' assert instead of rewriting the function completely. But you are right, that if it is compared to some value, the rewriting should be done.

I am working on a fix and am almost done with it, so a PR will follow in the next days. There are good chances that this comes in the next release.

@sallner
Copy link
Member

sallner commented Jun 28, 2016

@nicoddemus, @hpk42
it seems that is is rather complex to find exactly the conditions under which the rewrite is done as intended.
in case of

assert check_even(3) 
assert check_even(3)  and check_even(3)

there seems to be the intention to do no rewrite, but for the following:

assert check_even(3) == True
assert check_even(3) is True
assert check_even(3) > True
assert check_even(3) > 5
assert check_even(3) => True

and maybe other cases, it is not so easy to find a rule to rewrite it.

So again the question, do we want to change the rewrite in a way @cksagni91 suggested?

@sallner
Copy link
Member

sallner commented Jul 1, 2016

As it seems, the collapse_false() was removed completely (PR #1654) and this should also solve this issue. Can be closed now. @nicoddemus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants