1- import os
21import configparser
3- from typing import Dict , Any , Optional
2+ import os
3+ from typing import Any , Dict , Optional
44
55from .errors import ConfigurationError
66
@@ -19,10 +19,7 @@ class DynamicParamConfig:
1919 "dir" : ".pytest_cache/dynamic_params" ,
2020 },
2121 "validation" : {"level" : "strict" , "log_level" : "INFO" },
22- "performance" : {
23- "lazy_loading" : "true" ,
24- "incremental_generation" : "true"
25- },
22+ "performance" : {"lazy_loading" : "true" , "incremental_generation" : "true" },
2623 "debug" : {"enabled" : "false" , "profile" : "false" },
2724 }
2825
@@ -73,8 +70,7 @@ def _update_from_env(self, config: configparser.ConfigParser):
7370 "PYTEST_DYNAMIC_PARAM_VALIDATION" : "validation.level" ,
7471 "PYTEST_DYNAMIC_PARAM_LOG_LEVEL" : "validation.log_level" ,
7572 "PYTEST_DYNAMIC_PARAM_LAZY_LOADING" : "performance.lazy_loading" ,
76- "PYTEST_DYNAMIC_PARAM_INCREMENTAL" :
77- "performance.incremental_generation" ,
73+ "PYTEST_DYNAMIC_PARAM_INCREMENTAL" : "performance.incremental_generation" ,
7874 "PYTEST_DYNAMIC_PARAM_DEBUG" : "debug.enabled" ,
7975 "PYTEST_DYNAMIC_PARAM_PROFILE" : "debug.profile" ,
8076 "PYTEST_DYNAMIC_PARAM_CACHE_DIR" : "cache.dir" ,
@@ -88,13 +84,9 @@ def _update_from_env(self, config: configparser.ConfigParser):
8884 config [section ] = {}
8985 config [section ][option ] = os .environ [env_var ]
9086 except Exception as e :
91- print (
92- f"Warning: Failed to update config from { env_var } : { e } "
93- )
87+ print (f"Warning: Failed to update config from { env_var } : { e } " )
9488
95- def _normalize_config (
96- self , config : configparser .ConfigParser
97- ) -> Dict [str , Any ]:
89+ def _normalize_config (self , config : configparser .ConfigParser ) -> Dict [str , Any ]:
9890 """标准化配置值"""
9991 normalized = {}
10092
@@ -104,8 +96,7 @@ def _normalize_config(
10496 try :
10597 # 转换布尔值
10698 if value .lower () in ("true" , "false" ):
107- normalized [section ][key ] = \
108- config [section ].getboolean (key )
99+ normalized [section ][key ] = config [section ].getboolean (key )
109100 # 转换整数
110101 elif value .isdigit ():
111102 normalized [section ][key ] = config [section ].getint (key )
@@ -120,9 +111,7 @@ def _normalize_config(
120111
121112 return normalized
122113
123- def get (
124- self , section : str , option : str , default : Optional [Any ] = ...
125- ) -> Any :
114+ def get (self , section : str , option : str , default : Optional [Any ] = ...) -> Any :
126115 """获取配置值"""
127116 try :
128117 if section not in self ._config :
@@ -163,9 +152,7 @@ def validate(self) -> bool:
163152 valid_log_levels = ["DEBUG" , "INFO" , "WARNING" , "ERROR" ]
164153 if self .get ("validation" , "log_level" ) not in valid_log_levels :
165154 raise ConfigurationError (
166- "validation.log_level" ,
167- self .get ("validation" , "log_level" ),
168- str
155+ "validation.log_level" , self .get ("validation" , "log_level" ), str
169156 )
170157
171158 return True
0 commit comments