I recently found Googles pytruth package. I am very used to pytest and I am wondering what the value of the way less commonly used pytruth
is. The only reason why I didn't directly discard it, is that it comes from Google.
From the README, it seems to be mainly (only?) that you have the following ways to write assertions:
AssertThat(a).IsEqualTo(b) # 1
AssertThat(c).IsTrue() # 2
AssertThat(d).Contains(a) # 3
AssertThat(d).ContainsAllOf(a, b) # 4
AssertThat(d).ContainsAnyOf(a, b, c) # 5
with AssertThat(Error).IsRaised(): # 6
Explode()
AssertThat(result).ContainsExactlyElementsIn(expected) # 7
I am used to write the following:
assert a == b # 1
assert c # 2
assert a in d # 3
for element in [a, b]: # 4
assert element in d
assert any(element in d for element in [a, b, c]) # 5
with pytest.raises(Exception): # 6
Explode()
assert set(result) == set(expected) # 7
Is there any difference between what I was doing and the truth
package? Is there any reason to use the truth package? Is it maybe even considered good style?