Expose `SkipWithError` in Python bindings. (#968)

This commit is contained in:
Chris Jones 2020-05-28 09:33:06 +01:00 committed by GitHub
parent 9284e90f28
commit 6746c65bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -42,6 +42,7 @@ PYBIND11_MODULE(_benchmark, m) {
py::class_<benchmark::State>(m, "State")
.def("__bool__", &benchmark::State::KeepRunning)
.def_property_readonly("keep_running", &benchmark::State::KeepRunning);
.def_property_readonly("keep_running", &benchmark::State::KeepRunning)
.def("skip_with_error", &benchmark::State::SkipWithError);
};
} // namespace

View File

@ -28,5 +28,14 @@ def sum_million(state):
sum(range(1_000_000))
@benchmark.register
def skipped(state):
if True: # Test some predicate here.
state.skip_with_error('some error')
return # NOTE: You must explicitly return, or benchmark will continue.
... # Benchmark code would be here.
if __name__ == '__main__':
benchmark.main()