@@ -350,6 +350,7 @@ def check_query_result(
350350 retry_timeout = "0 seconds" ,
351351 retry_pause = "0.5 seconds" ,
352352 * ,
353+ assert_as_string = False ,
353354 replace_robot_variables = False ,
354355 selectStatement : Optional [str ] = None ,
355356 sansTran : Optional [bool ] = None ,
@@ -359,9 +360,11 @@ def check_query_result(
359360 The value position in results can be adjusted using ``row`` and ``col`` parameters (0-based).
360361 See `Inline assertions` for more details.
361362
362- *The assertion in this keyword is type sensitive!*
363- The ``expected_value`` is taken as a string, no argument conversion is performed.
364- Use RF syntax like ``${1}`` for numeric values.
363+ === Assertions are type sensitive! ===
364+ Normally, the type of ``expected_value`` is taken as provided (string as RF default or e.g. ``${1}`` for numeric values)
365+ and the type of *actual value* is taken as returned by the ``select_statement``
366+ (depends on the DB table and the Python module).
367+ Set ``assert_as_string`` to _True_ to convert both *actual value* and ``expected_value`` to string before running the assertion.
365368
366369 Use optional ``assertion_message`` to override the default error message.
367370
@@ -397,15 +400,32 @@ def check_query_result(
397400 """
398401 check_ok = False
399402 time_counter = 0
403+
404+ use_string_assertion_hint = "Consider using the 'assert_as_string' parameter."
405+
406+ def _log_possible_type_mismatch (expected , actual , suggest_string_assertion = True ):
407+ if actual is not None :
408+ msg = (
409+ f"Possible type mismatch between expected value '{ expected } ' ({ type (expected ).__name__ } ) "
410+ f"and actual value returned by the sql statement '{ actual } ' ({ type (actual ).__name__ } )."
411+ )
412+ if suggest_string_assertion :
413+ msg += f"\n { use_string_assertion_hint } "
414+ if type (expected ) != type (actual ):
415+ logger .info (msg )
416+
400417 while not check_ok :
401418 try :
419+ actual_value = None
420+
402421 query_results = self .query (
403422 select_statement ,
404423 no_transaction = no_transaction ,
405424 alias = alias ,
406425 parameters = parameters ,
407426 replace_robot_variables = replace_robot_variables ,
408427 )
428+
409429 row_count = len (query_results )
410430 assert (
411431 row < row_count
@@ -415,13 +435,33 @@ def check_query_result(
415435 col < col_count
416436 ), f"Checking column '{ col } ' is not possible, as query results contain { col_count } columns only!"
417437 actual_value = query_results [row ][col ]
438+ if assert_as_string :
439+ actual_value = str (actual_value )
440+ expected_value = str (expected_value )
441+
442+ assert_log_msg = (
443+ f"'{ actual_value } ' ({ type (actual_value ).__name__ } ) "
444+ f"{ assertion_operator .name } '{ expected_value } ' ({ type (expected_value ).__name__ } )"
445+ )
446+ logger .info (f"Run assertion: { assert_log_msg } " )
447+
418448 verify_assertion (
419- actual_value , assertion_operator , expected_value , "Wrong query result:" , assertion_message
449+ actual_value ,
450+ assertion_operator ,
451+ expected_value ,
452+ "Wrong query result:" ,
453+ assertion_message ,
420454 )
421455 check_ok = True
456+ except TypeError as e :
457+ _log_possible_type_mismatch (expected_value , actual_value , suggest_string_assertion = False )
458+ msg = f"Invalid assertion: { assert_log_msg } .\n { use_string_assertion_hint } \n "
459+ raise TypeError (f"{ msg } Original error: { e } " ) from e
460+
422461 except AssertionError as e :
423462 if time_counter >= timestr_to_secs (retry_timeout ):
424463 logger .info (f"Timeout '{ retry_timeout } ' reached" )
464+ _log_possible_type_mismatch (expected_value , actual_value )
425465 raise e
426466 BuiltIn ().sleep (retry_pause )
427467 time_counter += timestr_to_secs (retry_pause )
0 commit comments