Page MenuHomeSoftware Heritage

Make hypothesis strategies for swh-web stateless
Closed, MigratedEdits Locked

Description

Currently, the webapp's Hypothesis strategies rely on a storage set as a global variable, for instance:

def unknown_content():                                         
    """                                                        
    Hypothesis strategy returning a random content not ingested
    into the test archive.                                     
    """
    return new_content().filter(                               
        lambda c: next(storage.content_get(                    
            [hash_to_bytes(c['sha1'])])) is None)

However, that means that Hypothesis cannot replicate test failure once they happen if the content was added to the storage in the meantime:

E           hypothesis.errors.Flaky: Unreliable assumption: An example which satisfied assumptions on the first run now fails it.

and it completely hides the actual error, making debugging very hard.

Hypothesis is not designed to work with state, so we should get rid of it.