@@ -2351,3 +2351,48 @@ def test_install_8559_wheel_package_present(
2351
2351
allow_stderr_warning = False ,
2352
2352
)
2353
2353
assert DEPRECATION_MSG_PREFIX not in result .stderr
2354
+
2355
+
2356
+ @pytest .mark .skipif (
2357
+ sys .version_info < (3 , 11 ),
2358
+ reason = "3.11 required to find distributions via importlib metadata"
2359
+ )
2360
+ def test_install_existing_memory_distribution (script : PipTestEnvironment ):
2361
+ sitecustomize_text = textwrap .dedent (
2362
+ """
2363
+ import sys
2364
+ from importlib.metadata import Distribution, DistributionFinder
2365
+
2366
+
2367
+ EXAMPLE_METADATA = '''Metadata-Version: 2.1
2368
+ Name: example
2369
+ Version: 1.0.0
2370
+
2371
+ '''
2372
+
2373
+ class ExampleDistribution(Distribution):
2374
+ def locate_file(self, path):
2375
+ return path
2376
+
2377
+ def read_text(self, filename):
2378
+ if filename == 'METADATA':
2379
+ return EXAMPLE_METADATA
2380
+
2381
+
2382
+ class CustomFinder(DistributionFinder):
2383
+ def find_distributions(self, context=None):
2384
+ return [ExampleDistribution()]
2385
+
2386
+
2387
+ sys.meta_path.append(CustomFinder())
2388
+ """
2389
+ )
2390
+ with open (script .site_packages_path / 'sitecustomize.py' , 'w' ) as sitecustomize_file :
2391
+ sitecustomize_file .write (sitecustomize_text )
2392
+
2393
+ result = script .pip (
2394
+ "install" ,
2395
+ "example"
2396
+ )
2397
+
2398
+ assert "Requirement already satisfied: example in <memory>" in result .stdout
0 commit comments