def test_statistics_for_threshold_problem(): @settings(max_examples=100) @given(st.floats(min_value=0, allow_infinity=False)) def threshold(error): target(error, label="error") assert error <= 10 target(0.0, label="never in failing example") stats = call_for_statistics(threshold) assert " - Highest target scores:" in describe_statistics(stats) assert "never in failing example" in describe_statistics(stats) # Check that we report far-from-threshold failing examples assert stats["targets"]["error"] > 10
def test_exact_timing(): @settings(suppress_health_check=[HealthCheck.too_slow], deadline=None) @given(st.integers()) def test(i): time.sleep(0.5) stats = describe_statistics(call_for_statistics(test)) assert "~ 529ms" in stats
def test_statistics_with_events_and_target(): @given(st.sampled_from("1234")) def test(value): event(value) target(float(value), label="a target") stats = describe_statistics(call_for_statistics(test)) assert "- Events:" in stats assert "- Highest target score: " in stats
def test_apparently_instantaneous_tests(): time.freeze() @given(st.integers()) def test(i): pass stats = describe_statistics(call_for_statistics(test)) assert "< 1ms" in stats
def test_draw_time_percentage(draw_delay, test_delay): time.freeze() @st.composite def s(draw): if draw_delay: time.sleep(0.05) @given(s()) def test(_): if test_delay: time.sleep(0.05) stats = describe_statistics(call_for_statistics(test)) if not draw_delay: assert "~ 0%" in stats elif test_delay: assert "~ 50%" in stats else: assert "~ 100%" in stats
def note_statistics(stats): stats["nodeid"] = item.nodeid item.hypothesis_statistics = base64.b64encode( describe_statistics(stats).encode()).decode()
def note_statistics(stats): stats["nodeid"] = item.nodeid item.hypothesis_statistics = describe_statistics(stats)