Skip to content

Commit 3b930f0

Browse files
committed
fallback for monkeypatch in python 3.5
1 parent a559e58 commit 3b930f0

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

tests/test_auth_providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
@pytest.fixture(scope='module', params=[{'emulated': False}, {'emulated': True}])
5151
def user_mgt_app(request):
52-
monkeypatch = pytest.MonkeyPatch()
52+
monkeypatch = testutils.new_monkeypatch()
5353
if request.param['emulated']:
5454
monkeypatch.setenv(EMULATOR_HOST_ENV_VAR, AUTH_EMULATOR_HOST)
5555
monkeypatch.setitem(USER_MGT_URLS, 'ID_TOOLKIT', EMULATED_ID_TOOLKIT_URL)

tests/test_token_gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def auth_app(request):
148148
This can be used in any scenario where the private key is required. Use user_mgt_app
149149
for everything else.
150150
"""
151-
monkeypatch = pytest.MonkeyPatch()
151+
monkeypatch = testutils.new_monkeypatch()
152152
if request.param['emulated']:
153153
monkeypatch.setenv(EMULATOR_HOST_ENV_VAR, AUTH_EMULATOR_HOST)
154154
monkeypatch.setitem(TOKEN_MGT_URLS, 'ID_TOOLKIT', EMULATED_ID_TOOLKIT_URL)
@@ -159,7 +159,7 @@ def auth_app(request):
159159

160160
@pytest.fixture(scope='module', params=[{'emulated': False}, {'emulated': True}])
161161
def user_mgt_app(request):
162-
monkeypatch = pytest.MonkeyPatch()
162+
monkeypatch = testutils.new_monkeypatch()
163163
if request.param['emulated']:
164164
monkeypatch.setenv(EMULATOR_HOST_ENV_VAR, AUTH_EMULATOR_HOST)
165165
monkeypatch.setitem(TOKEN_MGT_URLS, 'ID_TOOLKIT', EMULATED_ID_TOOLKIT_URL)

tests/test_user_mgt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
@pytest.fixture(scope='module', params=[{'emulated': False}, {'emulated': True}])
6464
def user_mgt_app(request):
65-
monkeypatch = pytest.MonkeyPatch()
65+
monkeypatch = testutils.new_monkeypatch()
6666
if request.param['emulated']:
6767
monkeypatch.setenv(EMULATOR_HOST_ENV_VAR, AUTH_EMULATOR_HOST)
6868
monkeypatch.setitem(USER_MGT_URLS, 'ID_TOOLKIT', EMULATED_ID_TOOLKIT_URL)

tests/testutils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import io
1717
import os
1818

19+
import pytest
20+
1921
from google.auth import credentials
2022
from google.auth import transport
2123
from requests import adapters
@@ -58,6 +60,15 @@ def run_without_project_id(func):
5860
os.environ[env_var] = gcloud_project
5961

6062

63+
def new_monkeypatch():
64+
try:
65+
return pytest.MonkeyPatch()
66+
except AttributeError:
67+
# Fallback for Python 3.5
68+
from _pytest.monkeypatch import MonkeyPatch
69+
return MonkeyPatch()
70+
71+
6172
class MockResponse(transport.Response):
6273
def __init__(self, status, response):
6374
self._status = status

0 commit comments

Comments
 (0)