Skip to content

Commit

Permalink
test: use monkeypatch fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored and efiop committed Dec 28, 2023
1 parent 36746bb commit 1a8cd72
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pydrive2/test/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import time
import pytest
from pytest import MonkeyPatch

from pydrive2.auth import AuthenticationError, GoogleAuth
from pydrive2.test.test_util import (
Expand Down Expand Up @@ -190,25 +189,24 @@ def test_12_ServiceAuthFromJsonDictNoCredentialsSaving():
time.sleep(1)


def test_13_LocalWebServerAuthNonInterativeRaises():
def test_13_LocalWebServerAuthNonInterativeRaises(monkeypatch):
settings = {
"client_config_backend": "file",
"client_config_file": "client_secrets.json",
"oauth_scope": ["https://www.googleapis.com/auth/drive"],
}
ga = GoogleAuth(settings=settings)

with MonkeyPatch.context() as m:
m.setenv("GDRIVE_NON_INTERACTIVE", "true")
# Test that exception is raised on trying to do browser auth if
# we are running in a non interactive environment.
with pytest.raises(
AuthenticationError,
match=re.escape(
"Non interactive mode (GDRIVE_NON_INTERACTIVE env) is enabled"
),
):
ga.LocalWebserverAuth()
monkeypatch.setenv("GDRIVE_NON_INTERACTIVE", "true")
# Test that exception is raised on trying to do browser auth if
# we are running in a non interactive environment.
with pytest.raises(
AuthenticationError,
match=re.escape(
"Non interactive mode (GDRIVE_NON_INTERACTIVE env) is enabled"
),
):
ga.LocalWebserverAuth()


def CheckCredentialsFile(credentials, no_file=False):
Expand Down

0 comments on commit 1a8cd72

Please sign in to comment.