vendredi 5 mai 2017

Python Hypothesis - building strategy once for many tests?

I have a composite, expensive-to-build but cheap-to-test strategy. I must do:

@given(expensive_strategy())
def test_all(x):
    assert...
    assert...
    ...

It takes ~4 seconds to build the examples and negligible time to run the asserts.

Best practice dictates these tests be separated.

It is not clear to me how I could combine hypothesis strategies and eg. TestCase.setUp or pytest session-scoped fixtures. Both decorating the fixture and calling with x = expensive_strategy(); @given(x) does not help.

Aucun commentaire:

Enregistrer un commentaire