diff --git a/pandas/tests/io/json/test_compression.py b/pandas/tests/io/json/test_compression.py index c50b6f68b8839..46a5e511fe748 100644 --- a/pandas/tests/io/json/test_compression.py +++ b/pandas/tests/io/json/test_compression.py @@ -33,24 +33,19 @@ def test_read_zipped_json(datapath): @td.skip_if_not_us_locale -def test_with_s3_url(compression): - boto3 = pytest.importorskip('boto3') - pytest.importorskip('s3fs') - moto = pytest.importorskip('moto') +def test_with_s3_url(compression, s3_resource): + # Bucket "pandas-test" created in tests/io/conftest.py df = pd.read_json('{"a": [1, 2, 3], "b": [4, 5, 6]}') - with moto.mock_s3(): - conn = boto3.resource("s3", region_name="us-east-1") - bucket = conn.create_bucket(Bucket="pandas-test") - with tm.ensure_clean() as path: - df.to_json(path, compression=compression) - with open(path, 'rb') as f: - bucket.put_object(Key='test-1', Body=f) + with tm.ensure_clean() as path: + df.to_json(path, compression=compression) + with open(path, 'rb') as f: + s3_resource.Bucket("pandas-test").put_object(Key='test-1', Body=f) - roundtripped_df = pd.read_json('s3://pandas-test/test-1', - compression=compression) - assert_frame_equal(df, roundtripped_df) + roundtripped_df = pd.read_json('s3://pandas-test/test-1', + compression=compression) + assert_frame_equal(df, roundtripped_df) def test_lines_with_compression(compression): diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 564364ea01432..8cc3dee6648a8 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -723,25 +723,19 @@ def test_read_from_http_url(self, ext): local_table = self.get_exceldf('test1', ext) tm.assert_frame_equal(url_table, local_table) - @td.skip_if_no("s3fs") @td.skip_if_not_us_locale - def test_read_from_s3_url(self, ext): - moto = pytest.importorskip("moto") - boto3 = pytest.importorskip("boto3") - - with moto.mock_s3(): - conn = boto3.resource("s3", region_name="us-east-1") - conn.create_bucket(Bucket="pandas-test") - file_name = os.path.join(self.dirpath, 'test1' + ext) - - with open(file_name, "rb") as f: - conn.Bucket("pandas-test").put_object(Key="test1" + ext, - Body=f) - - url = ('s3://pandas-test/test1' + ext) - url_table = read_excel(url) - local_table = self.get_exceldf('test1', ext) - tm.assert_frame_equal(url_table, local_table) + def test_read_from_s3_url(self, ext, s3_resource): + # Bucket "pandas-test" created in tests/io/conftest.py + file_name = os.path.join(self.dirpath, 'test1' + ext) + + with open(file_name, "rb") as f: + s3_resource.Bucket("pandas-test").put_object(Key="test1" + ext, + Body=f) + + url = ('s3://pandas-test/test1' + ext) + url_table = read_excel(url) + local_table = self.get_exceldf('test1', ext) + tm.assert_frame_equal(url_table, local_table) @pytest.mark.slow # ignore warning from old xlrd