how to use a loop with pytest.mark.parametrize()
?
#9822
-
Hi, I'm new to pytest and fumbling my way about. I'm hoping someone has the time to point me in the right direction. This works: # x results in string 'gdalcompare'
# responses is a list: ['Usage: gdalcompare.py [-sds] <golden_file> <new_file>\n', '']
x = utils[12]
@pytest.mark.parametrize("input,want", [
pytest.param(x, {
"stdout": responses[x][0],
"stderr": responses[x][1],
})
]) But how can I now build on this so that for x in utils:
@pytest.mark.parametrize("input,want", [
pytest.param(x, {
"stdout": responses[x][0],
"stderr": responses[x][1],
})
]) Full script is at https://github.com/maphew/gdal/blob/pr-5281-redux/autotest/pyscripts/test_gdal_utils_cli.py. Note: this file and it's data files are the only ones written by me. Everything else is from others with more experience. I've been asking them enough for other help so I'm trying to spread things around. Thanks in advance for any attention you may spend on this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @maphew, The answer is to build the list of possible params = [
pytest.param(x, {
"stdout": responses[x][0],
"stderr": responses[x][1],
})
for x in utils
]
@pytest.mark.parametrize("input,want", params)
def test_program(input, want):
... |
Beta Was this translation helpful? Give feedback.
Hi @maphew,
The answer is to build the list of possible
pytest.param
values and pass that on topytest.mark.parametrize
: