Use monkeypatch.setenv instead of modifying os.environ (#4981)

This commit is contained in:
Asher Foa 2022-03-29 11:43:44 -04:00 committed by GitHub
parent 7a833637d1
commit 472b050aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 50 additions and 66 deletions

View File

@ -1,5 +1,4 @@
import boto3
import os
import pytest
import sure # noqa # pylint: disable=unused-import
import unittest
@ -20,12 +19,12 @@ def test_basic_decorator():
@pytest.fixture
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SECURITY_TOKEN"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.mark.network

View File

@ -3,19 +3,18 @@ import pytest
import sure # noqa # pylint: disable=unused-import
from moto import mock_s3
from moto import settings
from os import environ
from unittest import SkipTest
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
if settings.TEST_SERVER_MODE:
raise SkipTest("No point in testing this in ServerMode.")
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
def test_mock_works_with_client_created_inside(

View File

@ -1,5 +1,3 @@
from os import environ
import boto3
import pytest
@ -7,12 +5,12 @@ from moto import mock_efs
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,5 +1,3 @@
from os import environ
import boto3
import pytest
from botocore.exceptions import ClientError
@ -9,12 +7,12 @@ from moto.core import ACCOUNT_ID
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,5 +1,4 @@
import re
from os import environ
import boto3
import pytest
@ -32,12 +31,12 @@ SAMPLE_2_PARAMS = {
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,5 +1,3 @@
from os import environ
import boto3
import pytest
@ -7,12 +5,12 @@ from moto import mock_efs
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,5 +1,3 @@
from os import environ
import boto3
import pytest
from botocore.exceptions import ClientError
@ -8,12 +6,12 @@ from moto import mock_efs
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,6 +1,5 @@
import re
import sys
from os import environ
from ipaddress import IPv4Network
import boto3
@ -38,12 +37,12 @@ else:
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,5 +1,3 @@
from os import environ
import boto3
import pytest
from botocore.exceptions import ClientError
@ -8,12 +6,12 @@ from moto import mock_ec2, mock_efs
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")

View File

@ -1,6 +1,4 @@
import re
from os import environ
import pytest
from moto import mock_efs, mock_ec2
@ -12,12 +10,12 @@ MOUNT_TARGETS = "/2015-02-01/mount-targets"
@pytest.fixture(scope="function")
def aws_credentials():
def aws_credentials(monkeypatch):
"""Mocked AWS Credentials for moto."""
environ["AWS_ACCESS_KEY_ID"] = "testing"
environ["AWS_SESSION_TOKEN"] = "testing"
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
environ["AWS_SECURITY_TOKEN"] = "testing"
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
@pytest.fixture(scope="function")