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

RonnyPfannschmidt opensource at ronnypfannschmidt.de
Fri Oct 27 12:57:42 EDT 2017


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20171027/60b784be/attachment.html>


More information about the pytest-dev mailing list