@@ -107,7 +107,8 @@ def filter_args(addopts_args: list[str]) -> list[str]:
107107def modify_addopts (config_file : Path ) -> tuple [str , bool ]: # noqa : PLR0911
108108 file_type = config_file .suffix .lower ()
109109 filename = config_file .name
110- if file_type not in {".toml" , ".ini" , "cfg" } or not config_file .exists ():
110+ config = None
111+ if file_type not in {".toml" , ".ini" , ".cfg" } or not config_file .exists ():
111112 return "" , False
112113 # Read original file
113114 with Path .open (config_file , encoding = "utf-8" ) as f :
@@ -146,13 +147,13 @@ def modify_addopts(config_file: Path) -> tuple[str, bool]: # noqa : PLR0911
146147 f .write (tomlkit .dumps (data ))
147148 return content , True
148149 elif config_file .name in {"pytest.ini" , ".pytest.ini" , "tox.ini" }:
149- config [ "pytest" ][ "addopts" ] = " " .join (new_addopts_args )
150+ config . set ( "pytest" , "addopts" , " " .join (new_addopts_args ) )
150151 # Write modified file
151152 with Path .open (config_file , "w" , encoding = "utf-8" ) as f :
152153 config .write (f )
153154 return content , True
154155 else :
155- config [ "tool:pytest" ][ "addopts" ] = " " .join (new_addopts_args )
156+ config . set ( "tool:pytest" , "addopts" , " " .join (new_addopts_args ) )
156157 # Write modified file
157158 with Path .open (config_file , "w" , encoding = "utf-8" ) as f :
158159 config .write (f )
0 commit comments