Skip to content

Commit bd9ab53

Browse files
Technologicatclaude
andcommitted
use warn[] instead of error[] for missing optional dependencies in tests
Missing optional dependencies (sympy, mpmath) are expected in some environments, not failures. Using warn[] makes them show as warnings in the test report rather than errors, consistent with the semantic that the test is intentionally skipped. Updated documentation examples (fixtures.py docstring, README.md, doc/macros.md) to recommend the same pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ea83d4b commit bd9ab53

6 files changed

Lines changed: 22 additions & 13 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,14 @@ with session("simple framework demo"):
574574
try:
575575
import blargly
576576
except ImportError:
577-
error["blargly not installed, cannot test integration with it."]
577+
warn["blargly not installed, skipping integration tests."]
578578
else:
579579
... # blargly integration tests go here
580580

581+
# Unconditional errors and failures can be emitted with `error[]` and `fail[]`.
582+
# with testset("not implemented"):
583+
# fail["not implemented yet!"]
584+
581585
with testset(postproc=terminate):
582586
test[2 * 2 == 5] # fails, terminating the nearest dynamically enclosing `with session`
583587
test[2 * 2 == 4] # not reached

doc/macros.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,10 +1997,14 @@ with session("simple framework demo"):
19971997
try:
19981998
import blargly
19991999
except ImportError:
2000-
error["blargly not installed, cannot test integration with it."]
2000+
warn["blargly not installed, skipping integration tests."]
20012001
else:
20022002
... # blargly integration tests go here
20032003

2004+
# Unconditional errors and failures can be emitted with `error[]` and `fail[]`.
2005+
# with testset("not implemented"):
2006+
# fail["not implemented yet!"]
2007+
20042008
with testset(postproc=terminate):
20052009
test[2 * 2 == 5] # fails, terminating the nearest dynamically enclosing `with session`
20062010
test[2 * 2 == 4] # not reached

unpythonic/syntax/tests/test_nb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from ...syntax import macros, test, error # noqa: F401
3+
from ...syntax import macros, test, warn # noqa: F401
44
from ...test.fixtures import session, testset
55

66
from ...syntax import macros, nb # noqa: F401, F811
@@ -18,7 +18,7 @@ def runtests():
1818
try:
1919
from sympy import symbols, pprint
2020
except ImportError: # pragma: no cover
21-
error["SymPy not installed in this Python, cannot test symbolic math in nb."]
21+
warn["SymPy not installed in this Python, skipping symbolic math tests in nb."]
2222
else:
2323
with nb[pprint]: # you can specify a custom print function (first positional arg)
2424
test[_ is None] # noqa: F821

unpythonic/test/fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@
7474
with testset("inner 2"):
7575
test[2 + 2 == 4]
7676
77-
# Unconditional errors can be emitted with `error[]`.
77+
# Warnings can be emitted with `warn[]`.
7878
# Useful e.g. if an optional dependency is missing:
7979
with testset("integration"):
8080
try:
8181
import blargly
8282
except ImportError:
83-
error["blargly not installed, cannot test integration with it."]
83+
warn["blargly not installed, skipping integration tests."]
8484
else:
8585
... # blargly integration tests go here
8686
87-
# Similarly, unconditional errors can be emitted with `fail[]`.
87+
# Unconditional errors can be emitted with `error[]`.
88+
# Unconditional failures can be emitted with `fail[]`.
8889
# Useful for marking a testing TODO, or for marking a line
8990
# that should be unreachable in a code example.
9091
with testset("really fancy tests"):

unpythonic/tests/test_mathseq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from ..syntax import macros, test, test_raises, error, the # noqa: F401
3+
from ..syntax import macros, test, test_raises, warn, the # noqa: F401
44
from ..test.fixtures import session, testset
55

66
from operator import add, mul
@@ -27,7 +27,7 @@ def runtests():
2727
try:
2828
from sympy import symbols
2929
except ImportError: # pragma: no cover
30-
error["SymPy not installed in this Python, cannot test symbolic input for mathseq."]
30+
warn["SymPy not installed in this Python, skipping symbolic input tests for mathseq."]
3131
else:
3232
x = symbols("x", positive=True)
3333
test[sign(x) == +1]
@@ -40,7 +40,7 @@ def runtests():
4040
try:
4141
from sympy import symbols, exp as symbolicExp, E as NeperE
4242
except ImportError: # pragma: no cover
43-
error["SymPy not installed in this Python, cannot test symbolic input for mathseq."]
43+
warn["SymPy not installed in this Python, skipping symbolic input tests for mathseq."]
4444
else:
4545
test[log(NeperE**2) == 2]
4646
x = symbols("x", positive=True)
@@ -328,7 +328,7 @@ def runtests():
328328
try:
329329
from sympy import symbols
330330
except ImportError: # pragma: no cover
331-
error["SymPy not installed in this Python, cannot test symbolic input for mathseq."]
331+
warn["SymPy not installed in this Python, skipping symbolic input tests for mathseq."]
332332
else:
333333
x0 = symbols("x0", real=True)
334334
k = symbols("k", positive=True) # important for geometric series

unpythonic/tests/test_numutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from ..syntax import macros, test, test_raises, error, the # noqa: F401
3+
from ..syntax import macros, test, test_raises, warn, the # noqa: F401
44
from ..test.fixtures import session, testset
55

66
from itertools import count, takewhile
@@ -37,7 +37,7 @@ def runtests():
3737
try:
3838
from mpmath import mpf
3939
except ImportError: # pragma: no cover
40-
error["mpmath not installed in this Python, cannot test arbitrary precision input for mathseq."]
40+
warn["mpmath not installed in this Python, skipping arbitrary precision input tests."]
4141
else:
4242
test[almosteq(mpf(1.0), mpf(1.0 + ulp(1.0)))]
4343
test[almosteq(1.0, mpf(1.0 + ulp(1.0)))]

0 commit comments

Comments
 (0)