[pytest-dev] proposal - type-keyed storage for extension objects/metadata in config/items

Bruno Oliveira nicoddemus at gmail.com
Fri Oct 27 13:55:05 EDT 2017


Hi Ronny,

Can you provide a use case for this storage? Perhaps we can use existing
cases and see how they would like with the new API.

For example, pytest-html currently attaches an "extra" dictionary to items.
How could pytest-html make use of the new API?

Another example is the core junitxml plugin, which adds new items that
should go into the reporty by using a fixture. How it would look like to
customize the report using the new API?

Cheers,
Bruno.

On Fri, Oct 27, 2017 at 2:58 PM RonnyPfannschmidt <
opensource at ronnypfannschmidt.de> wrote:

> hi everyone
>
> since a while now i feel the lack of a place where i can store objects
> that belong to some pytest plugin but shouldn't be plugins themselves
>
> i came up with an idea for a basic api and would like to get feedback
> from it
>
> at the basic level there would be a `config.objects` or `item.objects`
> as "immutable" mapping with 4 extra methods to mutate, i#ll just show
> the proposed effects
>
> get_or_create(tp, *k, **kw):
>   if tp not in self:
>     self[tp] = tp(*k, **kw)
>   return self[tp]
> create(self, tp, *k, **kw):
>   if tp in self:
>     raise KeyError(tp)
>  self[tp] = tp(*k, **kw)
>  return self.tp
>
>  add(obj):
>   tp = type(obj)
>   if tp in self:
>     raise KeyError(tp)
>   self[tp] = obj
>
> remove(self, obj):
>   del self[type(obj)]
>
> discard(self, obj):
>   self.pop(type(obj), None)
>
> by adding such a storage it will be a lot more easy to just put things
> on items and reports
>
>
> -- Ronny
>
>
> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20171027/f14ad80e/attachment.html>


More information about the pytest-dev mailing list