python - Assertion not valid in script though type comparison works in terminal -
i encounter quite strange issue comparison.
i want decode python script arguments, store them , analyse them. in following command, -r option shall used determine type of report create.
python script launching : %run decodage_parametres_script.py -r junit,html
python script options parsing used fill dictionary, result is: current_options :
{'-cli-no-summary': false, '-cli-silent': false, '-r': ['junit', 'html']}
then want test -r options, here code:
for in current_options['-r']: # each reporter required -r option: # - check file path has been configured (otherwise set default) # - create file , initialize fields print("trace i", i) print("trace current_options['-r'] = ", current_options['-r']) print("trace current_options['-r'][0] = ", current_options['-r'][0]) if current_options['-r'][i] == 'junit': # request xml report file print("request xml export") try: xml_file_path = current_option['--reporter-junit-export'] print("xml file path = ", xml_file_path) except: # missing file configuration print("xml option - missing file path information") timestamp = get_timestamp() xml_file_path = 'default_report' + '_' + timestamp + '.xml' print("xml file path = ", xml_file_path) if xml_file_path not none: touch(xml_file_path) print("xml file path = ", xml_file_path) else: print('error: empty --reporter-junit-export path') sys.exit(0) else: print("no xml file required") i want try default report generation don't hit print("request xml export") line, here console result :
trace junit trace current_options['-r'] = ['junit', 'html'] trace current_options['-r'][0] = junit as guess type issue, tried following tests:
in [557]: in current_options['-r']: ...: print(i, type(i)) ...: junit <class 'str'> html <class 'str'> in [558]: toto = 'junit' in [559]: type(toto) out[559]: str in [560]: toto out[560]: 'junit' in [561]: toto == current_options['-r'][0] out[561]: true so line assertion if current_options['-r'][i] == 'junit': should end begin true it's not case. missing trivial ??? :(
can me, please ?
you iterating array of strings
for in current_options['-r']: in case i be:
junit on first iteration
html on next iteration
and if condition (from interpreter perspective) looks like:
if current_options['-r']['junit'] == 'junit': instead of expected:
if current_options['-r'][0] == 'junit': solution 1:
need iterate through of range(len(current_options['-r']))
solution 2
change comparator:
from
if current_options['-r'][i] == 'junit': to
if == 'junit':
Comments
Post a Comment