1
1
import os
2
2
import sys
3
3
import json
4
-
5
4
from .tracking import FunctionIndexer , get_full_function_name
6
5
7
6
@@ -35,6 +34,7 @@ def pytest_addoption(parser):
35
34
)
36
35
37
36
parser .addini ("ignore_func_names" , "function names to ignore" , "linelist" , [])
37
+ parser .addini ("json_path" , "path for saving json file" , "linelist" , [])
38
38
39
39
40
40
def pytest_load_initial_conftests (early_config , parser , args ):
@@ -47,6 +47,7 @@ class FuncCovPlugin:
47
47
def __init__ (self , args ):
48
48
self .args = args
49
49
self .indexer = FunctionIndexer (args .getini ("ignore_func_names" ))
50
+ self .json_path = args .getini ("json_path" )
50
51
51
52
def pytest_sessionstart (self , session ):
52
53
"""
@@ -153,14 +154,23 @@ def pytest_terminal_summary(self, terminalreporter):
153
154
total_cover = 0
154
155
155
156
args = ("TOTAL" , total_funcs , total_miss , total_cover )
157
+
156
158
if include_json :
157
159
report_data = {
158
160
"total_funcs" : total_funcs ,
159
161
"total_miss" : total_miss ,
160
162
"total_cover" : total_cover ,
161
163
}
162
- with open ("func_report.json" , "w" ) as json_file :
163
- json .dump (report_data , json_file , indent = 4 )
164
+
165
+ try :
166
+ file_path = os .path .join (self .json_path [0 ], "func_report.json" )
167
+ os .makedirs (self .json_path [0 ], exist_ok = True )
168
+ with open (file_path , "w" ) as json_file :
169
+ json .dump (report_data , json_file , indent = 4 )
170
+ except IndexError :
171
+ with open ("func_report.json" , "w" ) as json_file :
172
+ json .dump (report_data , json_file , indent = 4 )
173
+
164
174
if include_missing :
165
175
args += ("" ,)
166
176
0 commit comments