Hypothesis: Stateful: add multiple items to a bundle

Created on 18 May 2016  路  4Comments  路  Source: HypothesisWorks/hypothesis

I'd like to have steps in my stateful tests that depend on previous steps; IIUC bundles are a way to achieve that.

The problem is, puttings items into a bundle works via target=bundle in @rule, and I'd like to potentially generate several values per rule execution.

Edit to clarify: I'd like to have subsequent steps in my tests use values generated by prior steps, I'm aware of @precondition.

enhancement

Most helpful comment

It's a good idea, and I'm up for implementing it at some point. I think the API and how printing is handled require a bit of a rework to make it possible, but it's reasonably feasible from an internals point of view.

There are a bunch of higher priority things right now which mean improvements to stateful testing aren't really on the short term road map, so it probably won't happen soon though.

All 4 comments

Come to think of it, having a way of prepopulating bundles (from __init__) would be great too.

It's a good idea, and I'm up for implementing it at some point. I think the API and how printing is handled require a bit of a rework to make it possible, but it's reasonably feasible from an internals point of view.

There are a bunch of higher priority things right now which mean improvements to stateful testing aren't really on the short term road map, so it probably won't happen soon though.

Come to think of it, having a way of prepopulating bundles (from __init__) would be great too.

This is now covered by @initialize rules, which are run exactly once each prior to any other rule.

Do we already have a plan what the API for this should look like? My proposal would be

  • a function to wrap the results when returning, like: return multiple(result1, result2, result3)
  • since multiple() could be used to add no result to the bundle, it should have a convenient alias like return no_result().
Was this page helpful?
0 / 5 - 0 ratings