Pytest - How select test as failed and continue running the same test

Hi,
I am a new in Pytest.
I have a test running in loops, each loop will configure my HWR to different parameter, if some loop (with some Parameter) will fail i would like to continue running rest loops, but select the test as failed in pytest report.
How can i do this?

Thank you for the help

What do you mean running in loops? Are you using parametrize or fixtures, or have you written a loop?

By default, PyTest runs the entire suite (or filtered suite) and has to be told to stop on failure pytest -x or after a number of failures pytest —maxfail=3 explicitly.

Can you share the code?

Hello gpkesley’,
Thank you for responding.

For example I would like to know some way (not “assert”) to let this test finish all the loops, the test will executed by following pytest command:
os.system(‘pytest --log-cli-level=10’+
’ --log-format="%(asctime)s %(levelname)s %(message)s"’+
’ --log-date-format="%Y-%m-%d %H:%M:%S"’+
’ -o log_cli=true ’ +
path_to_test_suite + ’ --html=’ + html_report+
’ --self-contained-html -k "’ + test_cases_to_run)

My_Test.py

test_params = {‘Preset’:[‘1’,‘2’,‘3’],
‘FreqMode’:[‘1’,‘2’,‘3’],
‘FreqValue’:[‘1’,‘2’,‘3’],
‘Modulation’:[‘1’,‘2’,‘3’],
‘CommMode’:[‘1’,‘2’,‘3’],
‘PowerMode’:[‘1’,‘2’,‘3’],
‘PSVoltage’:[‘1’,‘2’,‘3’]}
def set_hwr(input):
print('input = '+str(input))
#— my function —
res=‘1’
return res

def test_myTest():
for Preset in test_params[‘Preset’]:
for FreqMode in test_params[‘FreqMode’]:
for FreqValue in test_params[‘FreqValue’]:
for Modulation in test_params[‘Modulation’]:
for CommMode in test_params[‘CommMode’]:
for PowerMode in test_params[‘PowerMode’]:
for PSVoltage in test_params[‘PSVoltage’]:
assert set_hwr(Preset)== ‘1’
assert set_hwr(FreqMode) == ‘2’
assert set_hwr(FreqValue) == ‘3’
assert set_hwr(Modulation) == ‘4’
assert set_hwr(CommMode) == ‘5’
assert set_hwr(PowerMode) == ‘6’
assert set_hwr(PSVoltage) == ‘7’

Yes, you can’t do this with a normal loop. You’ll you need to parameterize the test function.

1 Like

Indeed. Parametrize will help here and perhaps consider an excel import for the data if it changes a lot.