From 672a1233485926b1e9fdcb4170cb7b4e3abcb30b Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 20 Jan 2023 14:44:08 -0500 Subject: [PATCH] pytest: add global configfile and autouse teardown fixtures Signed-off-by: Casey Bodley --- s3tests/functional/__init__.py | 10 ++++++++++ s3tests/functional/test_headers.py | 2 ++ s3tests/functional/test_s3.py | 2 ++ s3tests/functional/test_s3_website.py | 2 ++ s3tests_boto3/functional/__init__.py | 11 +++++++++++ s3tests_boto3/functional/test_headers.py | 2 ++ s3tests_boto3/functional/test_iam.py | 2 ++ s3tests_boto3/functional/test_s3.py | 2 ++ s3tests_boto3/functional/test_s3select.py | 2 ++ s3tests_boto3/functional/test_sts.py | 2 ++ 10 files changed, 37 insertions(+) diff --git a/s3tests/functional/__init__.py b/s3tests/functional/__init__.py index 8911e02..a3890d4 100644 --- a/s3tests/functional/__init__.py +++ b/s3tests/functional/__init__.py @@ -7,6 +7,7 @@ import itertools import os import random import string +import pytest from http.client import HTTPConnection, HTTPSConnection from urllib.parse import urlparse @@ -370,6 +371,15 @@ def teardown(): # remove our buckets here also, to avoid littering nuke_prefixed_buckets(prefix=prefix) +@pytest.fixture(scope="package") +def configfile(): + setup() + yield config + +@pytest.fixture(autouse=True) +def setup_teardown(configfile): + yield + teardown() bucket_counter = itertools.count(1) diff --git a/s3tests/functional/test_headers.py b/s3tests/functional/test_headers.py index 63f0c56..f4415b7 100644 --- a/s3tests/functional/test_headers.py +++ b/s3tests/functional/test_headers.py @@ -27,6 +27,8 @@ from .utils import assert_raises from email.header import decode_header from . import ( + configfile, + setup_teardown, _make_raw_request, nuke_prefixed_buckets, get_new_bucket, diff --git a/s3tests/functional/test_s3.py b/s3tests/functional/test_s3.py index 808f9fa..db7dfb3 100644 --- a/s3tests/functional/test_s3.py +++ b/s3tests/functional/test_s3.py @@ -37,6 +37,8 @@ from .utils import assert_raises from .policy import Policy, Statement, make_json_policy from . import ( + configfile, + setup_teardown, nuke_prefixed_buckets, get_new_bucket, get_new_bucket_name, diff --git a/s3tests/functional/test_s3_website.py b/s3tests/functional/test_s3_website.py index 3696004..bd83468 100644 --- a/s3tests/functional/test_s3_website.py +++ b/s3tests/functional/test_s3_website.py @@ -19,6 +19,8 @@ from nose.plugins.skip import SkipTest from .. import common from . import ( + configfile, + setup_teardown, get_new_bucket, get_new_bucket_name, s3, diff --git a/s3tests_boto3/functional/__init__.py b/s3tests_boto3/functional/__init__.py index 4d03d65..22b136c 100644 --- a/s3tests_boto3/functional/__init__.py +++ b/s3tests_boto3/functional/__init__.py @@ -1,3 +1,4 @@ +import pytest import boto3 from botocore import UNSIGNED from botocore.client import Config @@ -308,6 +309,16 @@ def teardown(): except: pass +@pytest.fixture(scope="package") +def configfile(): + setup() + return config + +@pytest.fixture(autouse=True) +def setup_teardown(configfile): + yield + teardown() + def check_webidentity(): cfg = configparser.RawConfigParser() try: diff --git a/s3tests_boto3/functional/test_headers.py b/s3tests_boto3/functional/test_headers.py index 04b2757..a983c6e 100644 --- a/s3tests_boto3/functional/test_headers.py +++ b/s3tests_boto3/functional/test_headers.py @@ -10,6 +10,8 @@ from .utils import _get_status_and_error_code from .utils import _get_status from . import ( + configfile, + setup_teardown, get_client, get_v2_client, get_new_bucket, diff --git a/s3tests_boto3/functional/test_iam.py b/s3tests_boto3/functional/test_iam.py index bf7236f..e402356 100644 --- a/s3tests_boto3/functional/test_iam.py +++ b/s3tests_boto3/functional/test_iam.py @@ -7,6 +7,8 @@ from nose.tools import eq_ as eq from s3tests_boto3.functional.utils import assert_raises from s3tests_boto3.functional.test_s3 import _multipart_upload from . import ( + configfile, + setup_teardown, get_alt_client, get_iam_client, get_new_bucket, diff --git a/s3tests_boto3/functional/test_s3.py b/s3tests_boto3/functional/test_s3.py index 20ae4f1..1601809 100644 --- a/s3tests_boto3/functional/test_s3.py +++ b/s3tests_boto3/functional/test_s3.py @@ -41,6 +41,8 @@ from .utils import _get_status from .policy import Policy, Statement, make_json_policy from . import ( + configfile, + setup_teardown, get_client, get_prefix, get_unauthenticated_client, diff --git a/s3tests_boto3/functional/test_s3select.py b/s3tests_boto3/functional/test_s3select.py index 85d7c39..0b5ccda 100644 --- a/s3tests_boto3/functional/test_s3select.py +++ b/s3tests_boto3/functional/test_s3select.py @@ -9,6 +9,8 @@ import uuid from nose.tools import eq_ as eq from . import ( + configfile, + setup_teardown, get_client ) diff --git a/s3tests_boto3/functional/test_sts.py b/s3tests_boto3/functional/test_sts.py index dce1712..16b967c 100644 --- a/s3tests_boto3/functional/test_sts.py +++ b/s3tests_boto3/functional/test_sts.py @@ -32,6 +32,8 @@ from collections import namedtuple from email.header import decode_header from . import( + configfile, + setup_teardown, get_iam_client, get_sts_client, get_client,