August 2018
Beginner
160 pages
4h 8m
English
To solve all the above problems, pytest provides the much-loved @pytest.mark.parametrize mark. With this mark, you are able to provide a list of input values to the test, and pytest automatically generates multiple test functions for each input value.
The following shows this in action:
@pytest.mark.parametrize( "formula, inputs, result", [ ("C0 * x + 10", dict(x=1.0, C0=2.0), 12.0), ("sin(x) + 2 * cos(x)", dict(x=0.7), 2.1739021), ("log(x) + 3", dict(x=2.71828182846), 4.0), ],)def test_formula_parsing(formula, inputs, result): tokenizer = FormulaTokenizer() formula = Formula.from_string(formula, tokenizer) assert formula.eval(**inputs) == pytest.approx(result)
The @pytest.mark.parametrize mark automatically ...
Read now
Unlock full access