Answers for "pytest approx timedelta"

0

pytest approx timedelta

from datetime import timedelta
from pytest import approx

# 10.0 ± 2.0e+00
approx_expected_time = approx(
    timedelta(seconds=10).total_seconds(),
    abs=timedelta(seconds=2).total_seconds()
)

assert timedelta(seconds=13).total_seconds() == approx_expected_time    # false
assert timedelta(seconds=12).total_seconds() == approx_expected_time    # true
assert timedelta(seconds= 8).total_seconds() == approx_expected_time    # true
assert timedelta(seconds= 7).total_seconds() == approx_expected_time    # false
Posted by: Guest on September-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language