pytest: parametrized parameters with spaces are not executable individually
If the parameters of the parametrize are spaces, then the generated tests are not executable individually.
For instance, i just modify the example of the doc, by inserting a space in the test_input
values:
@pytest.mark.parametrize("test_input,expected", [
("3 5", 8),
("2 4", 6),
("6 9", 42),
])
def test_eval(test_input, expected):
assert eval(test_input.replace(' ', '+')) == expected
Execution:
pytest test.py
test.py::test_eval[3 5-8] PASSED
test.py::test_eval[2 4-6] PASSED
test.py::test_eval[6 9-42] FAILED
Note that the test ids contain spaces, so if I need to run just one test:
pytest test.py::test_eval[3 5-8]
I get an error cause the test id is interpreted as two tests test.py::test_eval[3
and 5-8]
that of course are not valid.
How can I solve this?
I guess a solution could be replace the space with a special character like \s
into the test nodeid.
Is there a way to modify the item.nodeid
of a test?
Thanks
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (7 by maintainers)
Some documented mechanism for quoting would definitely be welcome from my side.
I’m reluctant to add too much magic to it
@bluetech can we use quoted strings for the purpose?