[pytest-dev] [proposal] global and per item data stashes

Ronny Pfannschmidt rpfannsc at redhat.com
Tue Oct 15 09:03:11 EDT 2019


Problem: for the storage of helper objects that either tackle certain
global tracking details or that track information over the testprotocol
lifecycle of test items, we use monkeypatchs and generally just munge
around in either the pytest config object or item objects.

I would like to propose a new API putting those details into consideration.



  config.get_stash(owner, type=pytest.NamespaceStash) # valid over the
pytest session lifetime
  item.get_stash(owner, type=pytest.NamespaceStash) # valid across the
run-test protocol cycle of item

Each stash  would be a context manager and construction would get access to
both item and config.

This would for example enable to express the junit xml logger object and
configuration as

`config.get_stash(__name__, JunitXMlTracker)`

Just as  it would allow other plugin to store node lifecycle related
details within the node using a well known mechanism

Incidentally this would also be a good fit for the fixture system and
setup-state in general to store information.

The basic assumption being that only the stashes of the items that are
currently active are valid, and other stashes are torn down,
then fixtures as well as the fixture request would nicely fit that storage
mechanism, and would also generalize across the node tree from session down
to individual items.

(considering the layout, it might be sensible to even replace
config.get_stash with something
like session.get_stash)

The idea is still rather fuzzy in my head and i would love to di either
text based brainstorming on it, or a actual video call.

-- Ronny

Red Hat GmbH, http://www.de.redhat.com/, Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Michael Cunningham, Michael
O'Neill, Eric Shander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20191015/41a50bcc/attachment.html>


More information about the pytest-dev mailing list