@@ -17,6 +17,9 @@ def pytest_addoption(parser):
17
17
action = "store_true" , default = False ,
18
18
help = "run doctests in all .py modules" ,
19
19
dest = "doctestmodules" )
20
+ group .addoption ("--doctest-report" ,
21
+ type = str , default = "UDIFF" , choices = _get_report_choices ().keys (),
22
+ dest = "doctestreport" )
20
23
group .addoption ("--doctest-glob" ,
21
24
action = "append" , default = [], metavar = "pat" ,
22
25
help = "doctests file matching pattern, default: test*.txt" ,
@@ -94,7 +97,7 @@ def repr_failure(self, excinfo):
94
97
message = excinfo .type .__name__
95
98
reprlocation = ReprFileLocation (filename , lineno , message )
96
99
checker = _get_checker ()
97
- REPORT_UDIFF = doctest . REPORT_UDIFF
100
+ REPORT_UDIFF = _get_report_choices (). get ( self . config . getoption ( "doctestreport" ))
98
101
if lineno is not None :
99
102
lines = doctestfailure .test .docstring .splitlines (False )
100
103
# add line numbers to the left of the error message
@@ -291,6 +294,17 @@ def _get_allow_bytes_flag():
291
294
return doctest .register_optionflag ('ALLOW_BYTES' )
292
295
293
296
297
+ def _get_report_choices ():
298
+ import doctest
299
+ return dict (
300
+ UDIFF = doctest .REPORT_UDIFF ,
301
+ CDIFF = doctest .REPORT_CDIFF ,
302
+ NDIFF = doctest .REPORT_NDIFF ,
303
+ ONLY_FIRST_FAILURE = doctest .REPORT_ONLY_FIRST_FAILURE ,
304
+ NONE = 0 ,
305
+ )
306
+
307
+
294
308
@pytest .fixture (scope = 'session' )
295
309
def doctest_namespace ():
296
310
"""
0 commit comments