@@ -124,16 +124,18 @@ def pytest_addoption(parser):
124
124
help = "Test only doctests. Implies usage of doctest-plus." )
125
125
126
126
parser .addoption ("--doctest-plus-generate-diff" ,
127
- help = "Generate a diff for where expected output and real output "
128
- "differ. The diff is printed to stdout if not using "
129
- "`--doctest-plus-generate-diff=overwrite` which causes editing of "
130
- "the original files.\n "
131
- "NOTE: Unless an in-pace build is picked "
132
- "up, python file paths may point to unexpected places. "
133
- "If inplace is not used, will create a temporary folder and "
134
- "use `git diff -p` to generate a diff." ,
135
- choices = ["diff" , "overwrite" ],
136
- action = "store" , nargs = "?" , default = False , const = "diff" )
127
+ help = (
128
+ "Generate a diff for where expected output and real "
129
+ "output differ. "
130
+ "The diff is printed to stdout if not using "
131
+ "`--doctest-plus-generate-diff=overwrite` which "
132
+ "causes editing of the original files.\n "
133
+ "NOTE: Unless an in-pace build is picked up, python "
134
+ "file paths may point to unexpected places. "
135
+ "If inplace is not used, will create a temporary "
136
+ "folder and use `git diff -p` to generate a diff." ),
137
+ choices = ["diff" , "overwrite" ],
138
+ action = "store" , nargs = "?" , default = False , const = "diff" )
137
139
138
140
parser .addini ("text_file_format" ,
139
141
"Default format for docs. "
@@ -178,7 +180,7 @@ def pytest_addoption(parser):
178
180
179
181
def pytest_addhooks (pluginmanager ):
180
182
from pytest_doctestplus import newhooks
181
- method = pluginmanager .add_hookspecs (newhooks )
183
+ pluginmanager .add_hookspecs (newhooks )
182
184
183
185
184
186
def get_optionflags (parent ):
@@ -767,7 +769,7 @@ def write_modified_file(fname, new_fname, changes):
767
769
# Sort in reversed order to edit the lines:
768
770
bad_tests = []
769
771
changes .sort (key = lambda x : (x ["test_lineno" ], x ["example_lineno" ]),
770
- reverse = True )
772
+ reverse = True )
771
773
772
774
with open (fname , "r" ) as f :
773
775
text = f .readlines ()
@@ -878,14 +880,24 @@ class DebugRunnerPlus(doctest.DebugRunner):
878
880
_changesets = defaultdict (lambda : [])
879
881
_generate_diff = False
880
882
881
- def __init__ (self , checker = None , verbose = None , optionflags = 0 , continue_on_failure = True , generate_diff = False ):
883
+ def __init__ (self , checker = None , verbose = None , optionflags = 0 ,
884
+ continue_on_failure = True , generate_diff = False ):
882
885
# generated_diff is False, "diff", or "inplace" (only need truthiness)
883
886
DebugRunnerPlus ._generate_diff = generate_diff
884
887
885
888
super ().__init__ (checker = checker , verbose = verbose , optionflags = optionflags )
886
889
self .continue_on_failure = continue_on_failure
887
890
891
+ def report_success (self , out , test , example , got ):
892
+ if self ._generate_diff :
893
+ return self .track_diff (True , out , test , example , got )
894
+
895
+ return super ().report_success (out , test , example , got )
896
+
888
897
def report_failure (self , out , test , example , got ):
898
+ if self ._generate_diff :
899
+ self .track_diff (False , out , test , example , got )
900
+
889
901
failure = doctest .DocTestFailure (test , example , got )
890
902
if self .continue_on_failure :
891
903
out .append (failure )
@@ -913,24 +925,5 @@ def track_diff(self, use, out, test, example, got):
913
925
doctestplus_diffhook (info = info )
914
926
if not info ["use" ]:
915
927
return
916
- name = info ["name" ]
917
- filename = info ["filename" ]
918
- source = info ["source" ]
919
- test_lineno = info ["test_lineno" ]
920
- example_lineno = info ["example_lineno" ]
921
- want = info ["want" ]
922
- got = info ["got" ]
923
-
924
- self ._changesets [filename ].append (info )
925
-
926
- def report_success (self , out , test , example , got ):
927
- if self ._generate_diff :
928
- return self .track_diff (True , out , test , example , got )
929
-
930
- return super ().report_success (out , test , example , got )
931
-
932
- def report_failure (self , out , test , example , got ):
933
- if self ._generate_diff :
934
- self .track_diff (False , out , test , example , got )
935
928
936
- return super (). report_failure ( out , test , example , got )
929
+ self . _changesets [ info [ "filename" ]]. append ( info )
0 commit comments