Use monkeypatch.setenv instead of modifying os.environ (#4981)
This commit is contained in:
parent
7a833637d1
commit
472b050aad
@ -1,5 +1,4 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import os
|
|
||||||
import pytest
|
import pytest
|
||||||
import sure # noqa # pylint: disable=unused-import
|
import sure # noqa # pylint: disable=unused-import
|
||||||
import unittest
|
import unittest
|
||||||
@ -20,12 +19,12 @@ def test_basic_decorator():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
os.environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
os.environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.network
|
@pytest.mark.network
|
||||||
|
@ -3,19 +3,18 @@ import pytest
|
|||||||
import sure # noqa # pylint: disable=unused-import
|
import sure # noqa # pylint: disable=unused-import
|
||||||
from moto import mock_s3
|
from moto import mock_s3
|
||||||
from moto import settings
|
from moto import settings
|
||||||
from os import environ
|
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
if settings.TEST_SERVER_MODE:
|
if settings.TEST_SERVER_MODE:
|
||||||
raise SkipTest("No point in testing this in ServerMode.")
|
raise SkipTest("No point in testing this in ServerMode.")
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
def test_mock_works_with_client_created_inside(
|
def test_mock_works_with_client_created_inside(
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from os import environ
|
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -7,12 +5,12 @@ from moto import mock_efs
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from os import environ
|
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
@ -9,12 +7,12 @@ from moto.core import ACCOUNT_ID
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import re
|
import re
|
||||||
from os import environ
|
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
@ -32,12 +31,12 @@ SAMPLE_2_PARAMS = {
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from os import environ
|
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -7,12 +5,12 @@ from moto import mock_efs
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from os import environ
|
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
@ -8,12 +6,12 @@ from moto import mock_efs
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from os import environ
|
|
||||||
from ipaddress import IPv4Network
|
from ipaddress import IPv4Network
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
@ -38,12 +37,12 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from os import environ
|
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import pytest
|
import pytest
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
@ -8,12 +6,12 @@ from moto import mock_ec2, mock_efs
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import re
|
import re
|
||||||
from os import environ
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from moto import mock_efs, mock_ec2
|
from moto import mock_efs, mock_ec2
|
||||||
@ -12,12 +10,12 @@ MOUNT_TARGETS = "/2015-02-01/mount-targets"
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def aws_credentials():
|
def aws_credentials(monkeypatch):
|
||||||
"""Mocked AWS Credentials for moto."""
|
"""Mocked AWS Credentials for moto."""
|
||||||
environ["AWS_ACCESS_KEY_ID"] = "testing"
|
monkeypatch.setenv("AWS_ACCESS_KEY_ID", "testing")
|
||||||
environ["AWS_SESSION_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "testing")
|
||||||
environ["AWS_SECRET_ACCESS_KEY"] = "testing"
|
monkeypatch.setenv("AWS_SECURITY_TOKEN", "testing")
|
||||||
environ["AWS_SECURITY_TOKEN"] = "testing"
|
monkeypatch.setenv("AWS_SESSION_TOKEN", "testing")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user