python - Parametrize set of tests using PyTest -
python - Parametrize set of tests using PyTest -
i have next problem, need execute bunch of tests using pytest each test same, difference parameter.
for instance have execute:
./command_line arg1 ./command_line arg2 ... ./command_line argn
and need verify executable command returns expected given result.
i aware of this, inquire piece of advice best approach problem.
i give thanks in advance!
edit: found question in stackoverflow adviced take this page found useful in case.
i using pytest.mark.parametrize
, works this:
import pytest @pytest.mark.parametrize('arg, result', [ ('arg1', 'result1'), ('arg2', 'result2'), ('arg3', 'result3'), ('argn', 'resultn'), ]) def test_cmd0(arg, result): out = subprocess.check_output(['cmd', arg]) assert out.rstrip() == out
where arg1
, .. argn
- arguments, , result1
, .., resultn
expected results.
in illustration above, showed how launch external command , expect different result on every run. if expected result same, can skip result
in parametrization , do:
assert out.rstrip() == 'expected result'
python unit-testing testing py.test
Comments
Post a Comment