[pytest-dev] parametrization ids simplification/generalization
Brianna Laugher
brianna.laugher at gmail.com
Tue Oct 22 10:17:02 CEST 2013
So if you had this:
@py.test.mark.parametrize(('a', 'b', 'expected'), [
(1, 1, 2),
(1, 0, 1),
(1, -1, 0),
])
def test_addition(a, b, expected):
assert a + b == expected
what would the generated IDs be?
test_addition[a0-b0-expected0]
test_addition[a1-b1-expected1]
test_addition[a2-b2-expected2]
That just seems really pointless to me. If you're not going to display the
values at all, why bother including each parameter's name?
I was thinking
test_addition[0]
test_addition[1]
test_addition[2]
(again, as it already is if you parametrize using metafunc.addcall),
although I accept that is rather brief, maybe better as something like
test_addition[param0]
test_addition[param1]
test_addition[param2]
but basically I don't see the benefit of replicating how many parametrized
values there are, in each test id.
"-k arg0" is still going to be a pretty useless specification, just think
if you have multiple parametrized tests in a single file. I think whatever
solution here is not going to help the fact that you cannot specify an
entire test name as in "-k 'test_addition[param0]'" - which I think will be
fixed separately, as we discussed on issue #357.
cheers,
Brianna
On 22 October 2013 18:59, holger krekel <holger at merlinux.eu> wrote:
> On Tue, Oct 22, 2013 at 11:57 +1100, Brianna Laugher wrote:
> > I don't mind losing the IDs constructed from values, assuming it will
> still
> > be possible to specify IDs if using metafunc.addcall. But if we are going
> > to lose the IDs from values then they should probably just be plain
> > integers (as happens when using metafunc.addall without specifying id) -
> > having names like test_some[arg0-arg1-arg2], test_some[arg3-arg4-arg5]
> etc
> > is totally pointless.
>
> Including the argnames gives more context, no? Something like
> test_some[0-1-2] gives less. More importantly, selecting a specifically
> parametrized test works with "py.test -k arg0" whereas "py.test -k 1"
> would not work, i am afraid.
>
> best,
> holger
>
> > thanks
> > Brianna
> >
> >
> >
> > On 21 October 2013 23:12, holger krekel <holger at merlinux.eu> wrote:
> >
> > > Hi Brianna, all,
> > >
> > > I am thinking about constructing ids for parametrized tests using
> > > argname/valindex, i.e. not use the actual parametrization
> > > values. The latter causes some problems (among them also issue357)
> > > and generally doesn't allow to distinguish the two tests in:
> > >
> > > @pytest.mark.parametrize("arg", [1,1])
> > > def test_some(arg):
> > > pass
> > >
> > > Currently this gives two identical test ids "test_some[1]".
> > > With the new scheme this gives:
> > >
> > > test_some[arg0]
> > > test_some[arg1]
> > >
> > > Such a scheme would guarantee unique IDs. The scheme is already
> > > used for user instances.
> > >
> > > Note that when you get a traceback you would still see the actual
> > > argument values in the traceback.
> > >
> > > Any objections?
> > >
> > > holger
> > >
> >
> >
> >
> > --
> > They've just been waiting in a mountain for the right moment:
> > http://modernthings.org/
>
--
They've just been waiting in a mountain for the right moment:
http://modernthings.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20131022/87ba5501/attachment.html>
More information about the Pytest-dev
mailing list