summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-09-22 13:45:37 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2017-09-22 13:45:37 (GMT)
commiteef49f5dd021d15396551880cf451042a79a1107 (patch)
treee6032d3589e0e8600929cba82a5adbff1d3d0f63 /Lib/test
parent0c4997f1919d8583353b12537a63dcbe7b9d280f (diff)
downloadcpython-eef49f5dd021d15396551880cf451042a79a1107.zip
cpython-eef49f5dd021d15396551880cf451042a79a1107.tar.gz
cpython-eef49f5dd021d15396551880cf451042a79a1107.tar.bz2
bpo-31351: Set return code in ensurepip when pip fails (GH-3626) (GH-3683)
Previously ensurepip would always report success, even if the pip installation failed. (cherry picked from commit 9adda0cdf89432386b7a04444a6199b580d287a1) * Update version changed notice for backport
Diffstat (limited to 'Lib/test')
-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 9b04c18..8996689 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__":