@@ -90,3 +90,59 @@ def func():
90
90
# run all tests with pytest
91
91
result = pytester .inline_run (f , '--doctest-modules' )
92
92
assert result .ret == pytest .ExitCode .TESTS_FAILED
93
+
94
+
95
+ def test_alt_checker_doctestplus (pytester ):
96
+ """Test an alternative Checker, from pytest-doctestplus."""
97
+
98
+ pytest .importorskip ("pytest_doctestplus" )
99
+
100
+ # create a temporary conftest.py file
101
+ pytester .makeconftest (
102
+ """
103
+ import doctest
104
+ from scipy_doctest.conftest import dt_config
105
+
106
+ # hack!
107
+ from pytest_doctestplus.output_checker import OutputChecker as _OutputCheckerImpl
108
+
109
+ # DTChecker expectes a `config` ctor argument, add it
110
+ class PDPChecker(_OutputCheckerImpl):
111
+ def __init__(self, config):
112
+ super().__init__()
113
+
114
+ # Register the checker
115
+ dt_config.CheckerKlass = PDPChecker
116
+ """
117
+ )
118
+
119
+ # create a temporary pytest test file
120
+ src = (
121
+ """
122
+ def func():
123
+ '''
124
+ The doctest below, when run from the command line,
125
+ - passes with `pytest --doctest-modules --doctest-plus`, and
126
+ - fails without `--doctest-plus`.
127
+
128
+ We however run this doctest using the PDPChecker, so it picks up
129
+ the FLOAT_CMP directive from doctestplus without a command-line switch.
130
+
131
+ >>> 2/3 # doctest: +FLOAT_CMP
132
+ 0.666666
133
+ '''
134
+ pass
135
+ """
136
+ )
137
+
138
+ # run the doctest
139
+ f = pytester .makepyfile (src )
140
+ result = pytester .inline_run (f , '--doctest-modules' )
141
+ assert result .ret == pytest .ExitCode .OK
142
+
143
+ # remove the directive and rerun
144
+ src_ = src .replace ("# doctest: +FLOAT_CMP" , "" )
145
+ f_ = pytester .makepyfile (src_ )
146
+ result = pytester .inline_run (f_ , '--doctest-modules' )
147
+ assert result .ret == pytest .ExitCode .TESTS_FAILED
148
+
0 commit comments