From fc0ae5ee6b0c73f0399f67ade21b2e50ccddaa4a Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Thu, 2 Mar 2017 17:07:56 -0500 Subject: [PATCH] [cloud][test] Use pytest conditional imports instead of nose/SkipTest (#22019) --- .../cloud/amazon/test_ec2_vpc_nat_gateway.py | 16 ++++------------ .../modules/cloud/amazon/test_kinesis_stream.py | 16 ++++------------ test/units/modules/cloud/amazon/test_lambda.py | 7 +++---- test/units/modules/cloud/amazon/test_s3.py | 12 ++---------- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/test/units/modules/cloud/amazon/test_ec2_vpc_nat_gateway.py b/test/units/modules/cloud/amazon/test_ec2_vpc_nat_gateway.py index 6600219612d..61ea9a0b8e1 100644 --- a/test/units/modules/cloud/amazon/test_ec2_vpc_nat_gateway.py +++ b/test/units/modules/cloud/amazon/test_ec2_vpc_nat_gateway.py @@ -1,17 +1,9 @@ -from nose.plugins.skip import SkipTest - -try: - import boto3 - import botocore - HAS_BOTO3 = True -except ImportError: - HAS_BOTO3 = False - -if not HAS_BOTO3: - raise SkipTest("test_ec2_vpc_nat_gateway.py requires the python module 'boto3' and 'botocore'") - +import pytest import unittest +boto3 = pytest.importorskip("boto3") +botocore = pytest.importorskip("botocore") + from collections import namedtuple from ansible.parsing.dataloader import DataLoader from ansible.vars import VariableManager diff --git a/test/units/modules/cloud/amazon/test_kinesis_stream.py b/test/units/modules/cloud/amazon/test_kinesis_stream.py index efddfece7c8..5c908caf23d 100644 --- a/test/units/modules/cloud/amazon/test_kinesis_stream.py +++ b/test/units/modules/cloud/amazon/test_kinesis_stream.py @@ -1,17 +1,9 @@ -from nose.plugins.skip import SkipTest - -try: - import boto3 - import botocore - HAS_BOTO3 = True -except ImportError: - HAS_BOTO3 = False - -if not HAS_BOTO3: - raise SkipTest("test_kinesis_stream.py requires the python module 'boto3' and 'botocore'") - +import pytest import unittest +boto3 = pytest.importorskip("boto3") +botocore = pytest.importorskip("botocore") + import ansible.modules.cloud.amazon.kinesis_stream as kinesis_stream aws_region = 'us-west-2' diff --git a/test/units/modules/cloud/amazon/test_lambda.py b/test/units/modules/cloud/amazon/test_lambda.py index 1a55bce4065..db718df59f8 100644 --- a/test/units/modules/cloud/amazon/test_lambda.py +++ b/test/units/modules/cloud/amazon/test_lambda.py @@ -19,15 +19,14 @@ # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) -from nose.plugins.skip import SkipTest +import pytest +boto3 = pytest.importorskip("boto3") + import json import copy from ansible.module_utils._text import to_bytes from ansible.module_utils import basic from ansible.compat.tests.mock import MagicMock, Mock, patch -from ansible.module_utils.ec2 import HAS_BOTO3 -if not HAS_BOTO3: - raise SkipTest("test_ec2_asg.py requires the `boto3`, and `botocore` modules") # lambda is a keyword so we have to hack this. _temp = __import__("ansible.modules.cloud.amazon.lambda") diff --git a/test/units/modules/cloud/amazon/test_s3.py b/test/units/modules/cloud/amazon/test_s3.py index 25d1a3e39a8..b91f697825b 100644 --- a/test/units/modules/cloud/amazon/test_s3.py +++ b/test/units/modules/cloud/amazon/test_s3.py @@ -1,13 +1,5 @@ -from nose.plugins.skip import SkipTest - -try: - import boto - HAS_BOTO = True -except ImportError: - HAS_BOTO = False - -if not HAS_BOTO: - raise SkipTest("test_s3.py requires the python module 'boto'") +import pytest +boto = pytest.importorskip("boto") import unittest import ansible.modules.cloud.amazon.s3 as s3