]> arthur.barton.de Git - bup.git/commitdiff
wvpytest: add fail_value argument to wvpass and wvpasseq
authorRob Browning <rlb@defaultvalue.org>
Tue, 28 Jun 2022 21:37:00 +0000 (16:37 -0500)
committerRob Browning <rlb@defaultvalue.org>
Fri, 1 Jul 2022 19:17:05 +0000 (14:17 -0500)
This is analagous to the second, optional assert argument, although
unlike that one, it is of course always evaluated.

It can allow more informative failures:

  wvpasseq(re.split(r'[0-9]+', s), exp,
           "re.split(r'[0-9]+', %r) != %r" % (s, exp))

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
test/lib/wvpytest.py

index 523a3de51de5c45eade16c605f3eb90d0042cfd2..63eaa34f954117e90e7a54a745ca1ec372d8f5b1 100644 (file)
@@ -1,13 +1,19 @@
 import pytest
 
-def WVPASS(cond = True):
-    assert cond
+def WVPASS(cond = True, fail_value=None):
+    if fail_value:
+        assert cond, fail_value
+    else:
+        assert cond
 
 def WVFAIL(cond = True):
     assert not cond
 
-def WVPASSEQ(a, b):
-    assert a == b
+def WVPASSEQ(a, b, fail_value=None):
+    if fail_value:
+        assert a == b, fail_value
+    else:
+        assert a == b
 
 def WVPASSNE(a, b):
     assert a != b