@@ -414,6 +414,19 @@ def test_compare_code_reports_for_azure_mgmt_apimanagement_apistub():
414414 )
415415
416416
417+ def test_uninstall_package_uses_active_python_environment ():
418+ from breaking_changes_checker import detect_breaking_changes
419+
420+ with mock .patch .object (detect_breaking_changes .subprocess , "run" ) as run :
421+ detect_breaking_changes ._uninstall_package ("azure-mgmt-network" , "/tmp/azure-mgmt-network" )
422+
423+ run .assert_called_once_with (
424+ [sys .executable , "-m" , "pip" , "uninstall" , "-y" , "azure-mgmt-network" ],
425+ cwd = "/tmp/azure-mgmt-network" ,
426+ check = False ,
427+ )
428+
429+
417430def test_use_apistub_changelog_resolves_stable_from_pypi_and_current_from_local ():
418431 """``--use-apistub`` without ``-s`` must diff local source against the previous PyPI release.
419432
@@ -432,12 +445,17 @@ def test_use_apistub_changelog_resolves_stable_from_pypi_and_current_from_local(
432445 checker = mock .MagicMock ()
433446 checker .report_changes .return_value = ""
434447 checker .breaking_changes = []
448+ events = mock .Mock ()
435449
436450 with mock .patch ("pypi_tools.pypi.PyPIClient" , return_value = pypi_client ) as pypi_client_cls , mock .patch .object (
451+ detect_breaking_changes , "_uninstall_package"
452+ ) as uninstall_package , mock .patch .object (
437453 detect_breaking_changes , "build_report_from_apistub" , return_value = {}
438454 ) as build_report , mock .patch .object (
439455 detect_breaking_changes , "compare_report_dicts" , return_value = checker
440456 ) as compare :
457+ events .attach_mock (uninstall_package , "uninstall" )
458+ events .attach_mock (build_report , "build_report" )
441459 detect_breaking_changes .main (
442460 package_name = "azure-mgmt-network" ,
443461 target_module = "azure.mgmt.network" ,
@@ -453,6 +471,25 @@ def test_use_apistub_changelog_resolves_stable_from_pypi_and_current_from_local(
453471 )
454472
455473 assert build_report .call_count == 2 , "Expected separate apistub reports for current and stable"
474+ assert events .mock_calls == [
475+ mock .call .uninstall ("azure-mgmt-network" , "/tmp/azure-mgmt-network" ),
476+ mock .call .build_report (
477+ "azure-mgmt-network" ,
478+ "/tmp/azure-mgmt-network" ,
479+ version = "30.2.0" ,
480+ debug = False ,
481+ label = "stable" ,
482+ from_pypi = True ,
483+ ),
484+ mock .call .uninstall ("azure-mgmt-network" , "/tmp/azure-mgmt-network" ),
485+ mock .call .build_report (
486+ "azure-mgmt-network" ,
487+ "/tmp/azure-mgmt-network" ,
488+ debug = False ,
489+ label = "current" ,
490+ from_pypi = False ,
491+ ),
492+ ]
456493
457494 # The resolver must force the public PyPI backend: in CI PIP_INDEX_URL points
458495 # at the curated Azure Artifacts feed, which is not a full mirror of PyPI.
0 commit comments