Closed Peque closed 4 years ago
The for
loop is about the best way you can do this currently.
I suppose something like test.parametrize()
could take an array of parameters. I don't think that's worth including in AVA itself, at least at this stage. Perhaps somebody could publish a little package that wraps around AVA to provide this.
Let's leave this open for now for others to chime in.
But you have macros for that, just create a single macro and re-use it. That will make much more clearer code and dubegability.
maybe someone ought write a recipe for that and slap it in the docs. py.test
fans would eat that up :)
@novemberborn Has this been fixed? Or a recipe added to the docs? Or is the final resolution a "wont fix"?
Hey @Peque, per https://github.com/avajs/ava/issues/2414#issuecomment-593120059 I don't think we'll be adding this to AVA. Always open to link to examples or have a recipe, but IMHO it's not worth keeping this issue open for that.
I went ahead and published pava, which provides a simple utility for writing parameterized tests in ava!
@TomerAberbach nice, you should add it to https://github.com/avajs/awesome-ava!
Having a function like:
I would like to create multiple tests with multiple combinations of
a
andb
.Currently, I can do so by "brute force":
Or perhaps even better by using a
for
loop:It would be great to have a simple/clearer way to write this.
In Python, with the
pytest
framework, I can do:I think it is a great example. Note how I can define a list of possible values for each variable and how the name of the variable is assigned to the expected parameter in the test. The combinations are handled by the framework, so I do not need to create a list "by hand" to use in a
for
loop.It also allows you to do something like (for other use cases):