@@ -128,6 +128,32 @@ def add_pylint_checks() -> None:
128128 )
129129
130130
131+ def fix_default_fixture_scope () -> None :
132+ """Fix the default scope of fixtures to 'function'."""
133+ pyproject_toml = Path ("pyproject.toml" )
134+ print (f"{ pyproject_toml } : Fix the default scope of fixtures to 'function'." )
135+ marker = 'asyncio_mode = "auto"\n '
136+ pyproject_toml_content = pyproject_toml .read_text (encoding = "utf-8" )
137+ if pyproject_toml_content .find (marker ) == - 1 :
138+ manual_step (
139+ f"""\
140+ { pyproject_toml } : We couldn't find the marker { marker !r} in the file.
141+ Please add the following line to the file manually in the
142+ `[tool.pytest.ini_options]` section if it is missing:
143+ asyncio_default_fixture_loop_scope = "function"
144+ """
145+ )
146+ return
147+
148+ replacement = 'asyncio_default_fixture_loop_scope = "function"\n '
149+ if pyproject_toml_content .find (replacement ) >= 0 :
150+ print (f"{ pyproject_toml } : seems to be already up-to-date." )
151+ return
152+ replace_file_contents_atomically (
153+ pyproject_toml , marker , marker + replacement , content = pyproject_toml_content
154+ )
155+
156+
131157def main () -> None :
132158 """Run the migration steps."""
133159 # Dependabot patch
@@ -183,6 +209,10 @@ def main() -> None:
183209 manual_step (
184210 "Make sure that the `edit_uri` in the `mkdocs.yml` file points to the default branch."
185211 )
212+ print ("=" * 72 )
213+
214+ # Fix the default scope of fixtures to 'function'
215+ fix_default_fixture_scope ()
186216
187217 # Add a separation line like this one after each migration step.
188218 print ("=" * 72 )
0 commit comments