This repository was archived by the owner on Nov 1, 2026. It is now read-only.
Repository navigation
Read Behaviour changes below before upgrading.
TL;DR
| New | |
|---|---|
log_passes() |
logs each assertion that passes inside the block, with how far the value was from its bound (#57) |
| Passed when it should not have | |
|---|---|
assert_that(2).is_close_to(1, rel=0.5), and every rel= where the value is the larger number |
passed, the tolerance scaled with the larger of the two (#56) |
assert_that(1e308).is_close_to(-1e308, rel=1.9) |
passed, the difference and the allowance both overflowed to infinity |
log_passes() logs the assertions that pass
latency, status = 0.42, 200
with log_passes():
assert_that(latency).is_less_than(0.5)
assert_that(status).is_equal_to(200)
assert_that(98.7).is_close_to(100, 2)Before
ImportError: cannot import name 'log_passes' from 'assertpy2'
Now
[test_api.py:5]: is_less_than(0.5) passed for <0.42>, the value is about 0.08 below the number given
[test_api.py:6]: is_equal_to(200) passed for <200>
[test_api.py:7]: is_close_to(100, 2) passed for <98.7>, the two are about 1.3 apart, about 0.7 less than the tolerance
- Logger
assertpy2.passes, levelINFO. In pytest:-o log_cli=true --log-cli-level=INFO - The distance is given for thresholds:
is_less_than(),is_greater_than(),is_between(),is_close_to()and their kin on_pass=hands each pass to your code as anAssertionOutcome, the distance inhint- Only real passes: no line for soft or warn failures or under
check(). A poll logs the attempt that passed - Outside a block: one extra check per extension call and poll attempt, about 2 to 3%
Guide: Logging the assertions that pass, Handing each pass to your own code
rel= is a share of the expected value
assert_that(2).is_close_to(1, rel=0.5) # 1
assert_that(1e308).is_close_to(-1e308, rel=1.9) # 2
assert_that(2).is_not_close_to(1, rel=0.5) # 3Before
1: passed
2: passed
3: AssertionFailure: Expected <2> to not be close to <1> within relative tolerance <0.5>, but was.
Now
1: AssertionFailure: Expected <2> to be close to <1> within relative tolerance <0.5>, but was not.
2: AssertionFailure: Expected <1e+308> to be close to <-1e+308> within relative tolerance <1.9>, but was not.
3: passed
rel=0.5against1allows0.5either side, as inpytest.approx()andnumpy.testing.assert_allclose()- 2.33 took the share of the larger number, as
math.isclose()does, sorel=1passed any two numbers of one sign - Same for
is_equal_to(),snapshot(),matches_inline(),match.close_to()andmatch.equal_to()
Guide: Numbers
Behaviour changes
rel= on is_close_to(), is_not_close_to(), is_equal_to(), snapshot(), matches_inline(), match.close_to() and match.equal_to() |
is a share of the expected value. It was a share of the larger of the two, so a value above the expected one now gets a smaller allowance |
Everything else
- build: ty 0.0.95, ruff 0.17.3 and pytest 9.2.0
- ci: every suite runs on four workers by file, and coverage is measured only where it is reported
- test: the rich diff's child pytest runs in the suite's own interpreter