@@ -96,36 +96,46 @@ def test_distutils_has_origin():
96
96
97
97
98
98
ENSURE_IMPORTS_ARE_NOT_DUPLICATED = r"""
99
- # Depending on the importlib machinery and _distutils_hack, some imports can be
99
+ # Depending on the importlib machinery and _distutils_hack, some imports are
100
100
# duplicated resulting in different module objects being loaded, which prevents
101
- # patches from being applied as shown in #3042.
101
+ # patches as shown in #3042.
102
102
# This script provides a way of verifying if this duplication is happening.
103
103
104
+ from distutils import cmd
104
105
import distutils.command.sdist as sdist
105
106
106
107
# import last to prevent caching
107
- from distutils import dir_util, file_util, archive_util
108
+ from distutils import {imported_module}
108
109
109
- assert sdist.dir_util == dir_util, (
110
- f"\n{sdist.dir_util}\n!=\n{dir_util}"
111
- )
112
-
113
- assert sdist.file_util == file_util, (
114
- f"\n{sdist.file_util}\n!=\n{file_util}"
115
- )
116
-
117
- assert sdist.archive_util == archive_util, (
118
- f"\n{sdist.archive_util}\n!=\n{archive_util}"
119
- )
110
+ for mod in (cmd, sdist):
111
+ assert mod.{imported_module} == {imported_module}, (
112
+ f"\n{{mod.dir_util}}\n!=\n{{{imported_module}}}"
113
+ )
120
114
121
115
print("success")
122
116
"""
123
117
124
118
125
- @pytest .mark .parametrize ("distutils_version" , ("local" , "stdlib" ))
126
- def test_modules_are_not_duplicated_on_import (distutils_version , tmpdir_cwd , venv ):
119
+ @pytest .mark .parametrize (
120
+ "distutils_version, imported_module" ,
121
+ [
122
+ ("stdlib" , "dir_util" ),
123
+ ("stdlib" , "file_util" ),
124
+ ("stdlib" , "archive_util" ),
125
+ ("local" , "dir_util" ),
126
+ pytest .param (
127
+ "local" , "file_util" ,
128
+ marks = pytest .mark .xfail (reason = "duplicated distutils.file_util, #3042" )
129
+ ),
130
+ ("local" , "archive_util" ),
131
+ ]
132
+ )
133
+ def test_modules_are_not_duplicated_on_import (
134
+ distutils_version , imported_module , tmpdir_cwd , venv
135
+ ):
127
136
env = dict (SETUPTOOLS_USE_DISTUTILS = distutils_version )
128
- cmd = ['python' , '-c' , ENSURE_IMPORTS_ARE_NOT_DUPLICATED ]
137
+ script = ENSURE_IMPORTS_ARE_NOT_DUPLICATED .format (imported_module = imported_module )
138
+ cmd = ['python' , '-c' , script ]
129
139
output = popen_text (venv .run )(cmd , env = win_sr (env )).strip ()
130
140
assert output == "success"
131
141
0 commit comments