From 9603ed6048807be7ae78fabcf5add0c535703389 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 3 Feb 2022 14:52:16 -0800 Subject: [PATCH] TST: Create is_ci_environment helper --- pandas/compat/__init__.py | 16 +++++++++++++++- pandas/tests/io/conftest.py | 5 +++-- pandas/tests/io/parser/test_network.py | 4 ++-- pandas/tests/io/test_user_agent.py | 4 ++-- pandas/tests/io/xml/test_xml.py | 3 ++- pandas/tests/test_sorting.py | 8 +++++--- pandas/tests/window/test_numba.py | 6 ++---- pandas/tests/window/test_online.py | 6 ++---- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 0ce98038213d6..d0d7d6a1b8da6 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -7,6 +7,7 @@ Other items: * platform checker """ +import os import platform import sys @@ -89,7 +90,7 @@ def is_platform_mac() -> bool: def is_platform_arm() -> bool: """ - Checking if he running platform use ARM architecture. + Checking if the running platform use ARM architecture. Returns ------- @@ -101,6 +102,19 @@ def is_platform_arm() -> bool: ) +def is_ci_environment() -> bool: + """ + Checking if running in a continuous integration environment by checking + the PANDAS_CI environment variable. + + Returns + ------- + bool + True if the running in a continuous integration environment. + """ + return os.environ.get("PANDAS_CI", "0") == "1" + + def get_lzma_file(): """ Importing the `LZMAFile` class from the `lzma` module. diff --git a/pandas/tests/io/conftest.py b/pandas/tests/io/conftest.py index 7c9fd54059f4a..ff31d93947776 100644 --- a/pandas/tests/io/conftest.py +++ b/pandas/tests/io/conftest.py @@ -6,6 +6,7 @@ import pytest from pandas.compat import ( + is_ci_environment, is_platform_arm, is_platform_mac, is_platform_windows, @@ -42,7 +43,7 @@ def feather_file(datapath): @pytest.fixture def s3so(worker_id): - if os.environ.get("PANDAS_CI", "0") == "1": + if is_ci_environment(): url = "http://localhost:5000/" else: worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw") @@ -66,7 +67,7 @@ def s3_base(worker_id): # see https://github.com/spulec/moto/issues/1924 & 1952 os.environ.setdefault("AWS_ACCESS_KEY_ID", "foobar_key") os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "foobar_secret") - if os.environ.get("PANDAS_CI", "0") == "1": + if is_ci_environment(): if is_platform_arm() or is_platform_mac() or is_platform_windows(): # NOT RUN on Windows/MacOS/ARM, only Ubuntu # - subprocess in CI can cause timeouts diff --git a/pandas/tests/io/parser/test_network.py b/pandas/tests/io/parser/test_network.py index fb78a9aed7b13..f0e0bc46b6c74 100644 --- a/pandas/tests/io/parser/test_network.py +++ b/pandas/tests/io/parser/test_network.py @@ -7,11 +7,11 @@ StringIO, ) import logging -import os import numpy as np import pytest +from pandas.compat import is_ci_environment import pandas.util._test_decorators as td from pandas import DataFrame @@ -263,7 +263,7 @@ def test_read_csv_handles_boto_s3_object(self, s3_resource, tips_file): tm.assert_frame_equal(result, expected) @pytest.mark.skipif( - os.environ.get("PANDAS_CI", "0") == "1", + is_ci_environment(), reason="This test can hang in our CI min_versions build " "and leads to '##[error]The runner has " "received a shutdown signal...' in GHA. GH: 45651", diff --git a/pandas/tests/io/test_user_agent.py b/pandas/tests/io/test_user_agent.py index a5869e919f478..ac4ca5dce6dc3 100644 --- a/pandas/tests/io/test_user_agent.py +++ b/pandas/tests/io/test_user_agent.py @@ -5,20 +5,20 @@ import http.server from io import BytesIO import multiprocessing -import os import socket import time import urllib.error import pytest +from pandas.compat import is_ci_environment import pandas.util._test_decorators as td import pandas as pd import pandas._testing as tm pytestmark = pytest.mark.skipif( - os.environ.get("PANDAS_CI", "0") == "1", + is_ci_environment(), reason="This test can hang in our CI min_versions build " "and leads to '##[error]The runner has " "received a shutdown signal...' in GHA. GH 45651", diff --git a/pandas/tests/io/xml/test_xml.py b/pandas/tests/io/xml/test_xml.py index 76436d2358265..379b0898afa27 100644 --- a/pandas/tests/io/xml/test_xml.py +++ b/pandas/tests/io/xml/test_xml.py @@ -12,6 +12,7 @@ import numpy as np import pytest +from pandas.compat import is_ci_environment from pandas.compat._optional import import_optional_dependency import pandas.util._test_decorators as td @@ -1107,7 +1108,7 @@ def test_unsuported_compression(parser): @td.skip_if_no("s3fs") @td.skip_if_no("lxml") @pytest.mark.skipif( - os.environ.get("PANDAS_CI", "0") == "1", + is_ci_environment(), reason="2022.1.17: Hanging on the CI min versions build.", ) @tm.network diff --git a/pandas/tests/test_sorting.py b/pandas/tests/test_sorting.py index 374944a4e17c9..37820fe31b6db 100644 --- a/pandas/tests/test_sorting.py +++ b/pandas/tests/test_sorting.py @@ -1,12 +1,14 @@ from collections import defaultdict from datetime import datetime from itertools import product -import os import numpy as np import pytest -from pandas.compat import is_platform_windows +from pandas.compat import ( + is_ci_environment, + is_platform_windows, +) from pandas import ( DataFrame, @@ -428,7 +430,7 @@ def test_codes(self, verify, codes, exp_codes, na_sentinel): tm.assert_numpy_array_equal(result_codes, expected_codes) @pytest.mark.skipif( - is_platform_windows() and os.environ.get("PANDAS_CI", "0") == "1", + is_platform_windows() and is_ci_environment(), reason="In CI environment can crash thread with: " "Windows fatal exception: access violation", ) diff --git a/pandas/tests/window/test_numba.py b/pandas/tests/window/test_numba.py index 2c9ae3d70f218..89c575aa9f9ec 100644 --- a/pandas/tests/window/test_numba.py +++ b/pandas/tests/window/test_numba.py @@ -1,9 +1,8 @@ -import os - import numpy as np import pytest from pandas.compat import ( + is_ci_environment, is_platform_mac, is_platform_windows, ) @@ -21,8 +20,7 @@ # TODO(GH#44584): Mark these as pytest.mark.single pytestmark = pytest.mark.skipif( - os.environ.get("PANDAS_CI", "0") == "1" - and (is_platform_windows() or is_platform_mac()), + is_ci_environment() and (is_platform_windows() or is_platform_mac()), reason="On Azure CI, Windows can fail with " "'Windows fatal exception: stack overflow' " "and MacOS can timeout", diff --git a/pandas/tests/window/test_online.py b/pandas/tests/window/test_online.py index 543e5e4e545e0..c157b0e082405 100644 --- a/pandas/tests/window/test_online.py +++ b/pandas/tests/window/test_online.py @@ -1,9 +1,8 @@ -import os - import numpy as np import pytest from pandas.compat import ( + is_ci_environment, is_platform_mac, is_platform_windows, ) @@ -17,8 +16,7 @@ # TODO(GH#44584): Mark these as pytest.mark.single pytestmark = pytest.mark.skipif( - os.environ.get("PANDAS_CI", "0") == "1" - and (is_platform_windows() or is_platform_mac()), + is_ci_environment() and (is_platform_windows() or is_platform_mac()), reason="On Azure CI, Windows can fail with " "'Windows fatal exception: stack overflow' " "and MacOS can timeout",