Exception handling and testing with pytest and hypothesis
问题 I'm writing tests for a statistical analysis with hypothesis. Hypothesis led me to a ZeroDivisionError in my code when it is passed very sparse data. So I adapted my code to handle the exception; in my case, that means log the reason and reraise the exception. try: val = calc(data) except ZeroDivisionError: logger.error(f"check data: {data}, too sparse") raise I need to pass the exception up through the call stack because the top-level caller needs to know there was an exception so that it