summaryrefslogtreecommitdiff
path: root/Lib/test/test_ensurepip.py
diff options
context:
space:
mode:
authorIgor Filatov <iafilatov@users.noreply.github.com>2017-09-21 13:07:45 +0300
committerNick Coghlan <ncoghlan@gmail.com>2017-09-21 20:07:45 +1000
commit9adda0cdf89432386b7a04444a6199b580d287a1 (patch)
treef43b624c8d4fb6cbfc70ee2070084e5f4dd2c2c2 /Lib/test/test_ensurepip.py
parenta96c96f5dab68d4e611af4b8caefd7268533fd9a (diff)
downloadcpython-git-9adda0cdf89432386b7a04444a6199b580d287a1.tar.gz
bpo-31351: Set return code in ensurepip when pip fails (GH-3626)
Previously ensurepip would always report success, even if the pip installation failed.
Diffstat (limited to 'Lib/test/test_ensurepip.py')
-rw-r--r--Lib/test/test_ensurepip.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py
index 9b04c18b0e..8996689309 100644
--- a/Lib/test/test_ensurepip.py
+++ b/Lib/test/test_ensurepip.py
@@ -20,6 +20,7 @@ class EnsurepipMixin:
def setUp(self):
run_pip_patch = unittest.mock.patch("ensurepip._run_pip")
self.run_pip = run_pip_patch.start()
+ self.run_pip.return_value = 0
self.addCleanup(run_pip_patch.stop)
# Avoid side effects on the actual os module
@@ -255,7 +256,7 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
self.assertFalse(self.run_pip.called)
def test_basic_bootstrapping(self):
- ensurepip._main([])
+ exit_code = ensurepip._main([])
self.run_pip.assert_called_once_with(
[
@@ -267,6 +268,13 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
additional_paths = self.run_pip.call_args[0][1]
self.assertEqual(len(additional_paths), 2)
+ self.assertEqual(exit_code, 0)
+
+ def test_bootstrapping_error_code(self):
+ self.run_pip.return_value = 2
+ exit_code = ensurepip._main([])
+ self.assertEqual(exit_code, 2)
+
class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
@@ -280,7 +288,7 @@ class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
def test_basic_uninstall(self):
with fake_pip():
- ensurepip._uninstall._main([])
+ exit_code = ensurepip._uninstall._main([])
self.run_pip.assert_called_once_with(
[
@@ -289,6 +297,13 @@ class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
]
)
+ self.assertEqual(exit_code, 0)
+
+ def test_uninstall_error_code(self):
+ with fake_pip():
+ self.run_pip.return_value = 2
+ exit_code = ensurepip._uninstall._main([])
+ self.assertEqual(exit_code, 2)
if __name__ == "__main__":