hamcrest: how to input Boolean value

279 views Asked by At

I am not sure why I see error when I have this code. all_is_valid is highlighted in yellow and when I hover over I see below error message. How do I avoid not highlighting it?

Expected type 'Matcher[bool]' (matched generic type 'Matcher[T]'), got 'bool' instead

all_is_valid=True  
actual = None
if not actual:
    all_is_valid = False
    assert_that(True, all_is_valid,"test failed")
1

There are 1 answers

1
Sudhir Sharma On

Trying to convert your input to bool won't work like that. Python considers any non-empty string True. So doing bool(input()) is basically the same as doing input() != ''. Both return true even if the input wasn't "True". Just compare the input given directly to the strings "True and "False":`isTrue = True while isTrue:

isTrue = bool(int(input("Continue? 1 for yes, 0 for no: ")))`