Skip to content

Commit 7dc1724

Browse files
mroeschkephofl
authored andcommitted
TST: Create is_ci_environment helper (pandas-dev#45812)
1 parent 8316df9 commit 7dc1724

File tree

8 files changed

+33
-19
lines changed

8 files changed

+33
-19
lines changed

pandas/compat/__init__.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Other items:
88
* platform checker
99
"""
10+
import os
1011
import platform
1112
import sys
1213

@@ -89,7 +90,7 @@ def is_platform_mac() -> bool:
8990

9091
def is_platform_arm() -> bool:
9192
"""
92-
Checking if he running platform use ARM architecture.
93+
Checking if the running platform use ARM architecture.
9394
9495
Returns
9596
-------
@@ -101,6 +102,19 @@ def is_platform_arm() -> bool:
101102
)
102103

103104

105+
def is_ci_environment() -> bool:
106+
"""
107+
Checking if running in a continuous integration environment by checking
108+
the PANDAS_CI environment variable.
109+
110+
Returns
111+
-------
112+
bool
113+
True if the running in a continuous integration environment.
114+
"""
115+
return os.environ.get("PANDAS_CI", "0") == "1"
116+
117+
104118
def get_lzma_file():
105119
"""
106120
Importing the `LZMAFile` class from the `lzma` module.

pandas/tests/io/conftest.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from pandas.compat import (
9+
is_ci_environment,
910
is_platform_arm,
1011
is_platform_mac,
1112
is_platform_windows,
@@ -42,7 +43,7 @@ def feather_file(datapath):
4243

4344
@pytest.fixture
4445
def s3so(worker_id):
45-
if os.environ.get("PANDAS_CI", "0") == "1":
46+
if is_ci_environment():
4647
url = "http://localhost:5000/"
4748
else:
4849
worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
@@ -66,7 +67,7 @@ def s3_base(worker_id):
6667
# see https://github.com/spulec/moto/issues/1924 & 1952
6768
os.environ.setdefault("AWS_ACCESS_KEY_ID", "foobar_key")
6869
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "foobar_secret")
69-
if os.environ.get("PANDAS_CI", "0") == "1":
70+
if is_ci_environment():
7071
if is_platform_arm() or is_platform_mac() or is_platform_windows():
7172
# NOT RUN on Windows/MacOS/ARM, only Ubuntu
7273
# - subprocess in CI can cause timeouts

pandas/tests/io/parser/test_network.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
StringIO,
88
)
99
import logging
10-
import os
1110

1211
import numpy as np
1312
import pytest
1413

14+
from pandas.compat import is_ci_environment
1515
import pandas.util._test_decorators as td
1616

1717
from pandas import DataFrame
@@ -263,7 +263,7 @@ def test_read_csv_handles_boto_s3_object(self, s3_resource, tips_file):
263263
tm.assert_frame_equal(result, expected)
264264

265265
@pytest.mark.skipif(
266-
os.environ.get("PANDAS_CI", "0") == "1",
266+
is_ci_environment(),
267267
reason="This test can hang in our CI min_versions build "
268268
"and leads to '##[error]The runner has "
269269
"received a shutdown signal...' in GHA. GH: 45651",

pandas/tests/io/test_user_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
import http.server
66
from io import BytesIO
77
import multiprocessing
8-
import os
98
import socket
109
import time
1110
import urllib.error
1211

1312
import pytest
1413

14+
from pandas.compat import is_ci_environment
1515
import pandas.util._test_decorators as td
1616

1717
import pandas as pd
1818
import pandas._testing as tm
1919

2020
pytestmark = pytest.mark.skipif(
21-
os.environ.get("PANDAS_CI", "0") == "1",
21+
is_ci_environment(),
2222
reason="This test can hang in our CI min_versions build "
2323
"and leads to '##[error]The runner has "
2424
"received a shutdown signal...' in GHA. GH 45651",

pandas/tests/io/xml/test_xml.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313
import pytest
1414

15+
from pandas.compat import is_ci_environment
1516
from pandas.compat._optional import import_optional_dependency
1617
import pandas.util._test_decorators as td
1718

@@ -1107,7 +1108,7 @@ def test_unsuported_compression(parser):
11071108
@td.skip_if_no("s3fs")
11081109
@td.skip_if_no("lxml")
11091110
@pytest.mark.skipif(
1110-
os.environ.get("PANDAS_CI", "0") == "1",
1111+
is_ci_environment(),
11111112
reason="2022.1.17: Hanging on the CI min versions build.",
11121113
)
11131114
@tm.network

pandas/tests/test_sorting.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from collections import defaultdict
22
from datetime import datetime
33
from itertools import product
4-
import os
54

65
import numpy as np
76
import pytest
87

9-
from pandas.compat import is_platform_windows
8+
from pandas.compat import (
9+
is_ci_environment,
10+
is_platform_windows,
11+
)
1012

1113
from pandas import (
1214
DataFrame,
@@ -428,7 +430,7 @@ def test_codes(self, verify, codes, exp_codes, na_sentinel):
428430
tm.assert_numpy_array_equal(result_codes, expected_codes)
429431

430432
@pytest.mark.skipif(
431-
is_platform_windows() and os.environ.get("PANDAS_CI", "0") == "1",
433+
is_platform_windows() and is_ci_environment(),
432434
reason="In CI environment can crash thread with: "
433435
"Windows fatal exception: access violation",
434436
)

pandas/tests/window/test_numba.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import os
2-
31
import numpy as np
42
import pytest
53

64
from pandas.compat import (
5+
is_ci_environment,
76
is_platform_mac,
87
is_platform_windows,
98
)
@@ -21,8 +20,7 @@
2120

2221
# TODO(GH#44584): Mark these as pytest.mark.single
2322
pytestmark = pytest.mark.skipif(
24-
os.environ.get("PANDAS_CI", "0") == "1"
25-
and (is_platform_windows() or is_platform_mac()),
23+
is_ci_environment() and (is_platform_windows() or is_platform_mac()),
2624
reason="On Azure CI, Windows can fail with "
2725
"'Windows fatal exception: stack overflow' "
2826
"and MacOS can timeout",

pandas/tests/window/test_online.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import os
2-
31
import numpy as np
42
import pytest
53

64
from pandas.compat import (
5+
is_ci_environment,
76
is_platform_mac,
87
is_platform_windows,
98
)
@@ -17,8 +16,7 @@
1716

1817
# TODO(GH#44584): Mark these as pytest.mark.single
1918
pytestmark = pytest.mark.skipif(
20-
os.environ.get("PANDAS_CI", "0") == "1"
21-
and (is_platform_windows() or is_platform_mac()),
19+
is_ci_environment() and (is_platform_windows() or is_platform_mac()),
2220
reason="On Azure CI, Windows can fail with "
2321
"'Windows fatal exception: stack overflow' "
2422
"and MacOS can timeout",

0 commit comments

Comments
 (0)