11"""Tests for the config command"""
22
3+ from __future__ import annotations
4+
35import os
46import re
57import textwrap
8+ from collections .abc import Generator
9+
10+ import pytest
611
712from pip ._internal .cli .status_codes import ERROR
813from pip ._internal .configuration import CONFIG_BASENAME , get_configuration_files
@@ -18,6 +23,15 @@ def test_no_options_passed_should_error(script: PipTestEnvironment) -> None:
1823
1924
2025class TestBasicLoading (ConfigurationMixin ):
26+ @pytest .fixture (autouse = True )
27+ def cleanup_files (self ) -> Generator [None ]:
28+ """Avoid state leaking for tests reusing config files."""
29+ yield
30+ for variant in get_configuration_files ():
31+ for path in variant :
32+ if os .path .exists (path ):
33+ os .remove (path )
34+
2135 def test_basic_modification_pipeline (self , script : PipTestEnvironment ) -> None :
2236 script .pip ("config" , "get" , "test.blah" , expect_error = True )
2337 script .pip ("config" , "set" , "test.blah" , "1" )
@@ -112,9 +126,6 @@ def test_user_values(self, script: PipTestEnvironment) -> None:
112126 assert "freeze.timeout: 10" in result .stdout
113127 assert re .search (r"user:\n( .+\n)+" , result .stdout )
114128
115- # Avoid state leaking for tests reusing the new config file
116- os .remove (new_config_file )
117-
118129 def test_site_values (
119130 self , script : PipTestEnvironment , virtualenv : VirtualEnvironment
120131 ) -> None :
@@ -146,10 +157,6 @@ def test_global_config_file(self, script: PipTestEnvironment) -> None:
146157 result = script .pip ("config" , "debug" )
147158 assert f"{ global_config_file } , exists:" in result .stdout
148159
149- # Avoid state leaking for tests reusing the new config file
150- if os .path .exists (global_config_file ):
151- os .remove (global_config_file )
152-
153160 def test_editor_does_not_exist (self , script : PipTestEnvironment ) -> None :
154161 """Ensure that FileNotFoundError sets filename correctly"""
155162 result = script .pip (
0 commit comments