From 9b63f9cd37d19f2d4bbce42caec112ad0606d8dd Mon Sep 17 00:00:00 2001
From: Cory Benfield <lukasaoz@gmail.com>
Date: Thu, 22 Oct 2015 12:22:28 +0100
Subject: [PATCH] Make sure we unapply this patch.
---
test_requests.py | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/test_requests.py b/test_requests.py
index d1c6aa4d5..cb25555aa 100755
--- a/test_requests.py
+++ b/test_requests.py
@@ -353,28 +353,33 @@ def test_basicauth_with_netrc(self):
wrong_auth = ('wronguser', 'wrongpass')
url = httpbin('basic-auth', 'user', 'pass')
- def get_netrc_auth_mock(url):
- return auth
- requests.sessions.get_netrc_auth = get_netrc_auth_mock
+ old_auth = requests.sessions.get_netrc_auth
- # Should use netrc and work.
- r = requests.get(url)
- assert r.status_code == 200
-
- # Given auth should override and fail.
- r = requests.get(url, auth=wrong_auth)
- assert r.status_code == 401
-
- s = requests.session()
-
- # Should use netrc and work.
- r = s.get(url)
- assert r.status_code == 200
-
- # Given auth should override and fail.
- s.auth = wrong_auth
- r = s.get(url)
- assert r.status_code == 401
+ try:
+ def get_netrc_auth_mock(url):
+ return auth
+ requests.sessions.get_netrc_auth = get_netrc_auth_mock
+
+ # Should use netrc and work.
+ r = requests.get(url)
+ assert r.status_code == 200
+
+ # Given auth should override and fail.
+ r = requests.get(url, auth=wrong_auth)
+ assert r.status_code == 401
+
+ s = requests.session()
+
+ # Should use netrc and work.
+ r = s.get(url)
+ assert r.status_code == 200
+
+ # Given auth should override and fail.
+ s.auth = wrong_auth
+ r = s.get(url)
+ assert r.status_code == 401
+ finally:
+ requests.sessions.get_netrc_auth = old_auth
def test_DIGEST_HTTP_200_OK_GET(self):