Skip to content

Commit 3ac3ced

Browse files
committed
TST: Test bz2 non-import from subprocess
1 parent 1ab1045 commit 3ac3ced

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

pandas/tests/test_common.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import numpy as np
88
import pytest
99

10-
sys.modules.pop("bz2", None) # Remove 'bz2' from available modules for testing
11-
from pandas.compat import get_bz2_file
12-
1310
import pandas as pd
1411
from pandas import Series
1512
import pandas._testing as tm
@@ -18,13 +15,6 @@
1815
from pandas.util.version import Version
1916

2017

21-
def test_bz2_nonimport():
22-
assert "bz2" not in sys.modules
23-
msg = "bz2 module not available."
24-
with pytest.raises(RuntimeError, match=msg):
25-
get_bz2_file()
26-
27-
2818
def test_get_callable_name():
2919
getname = com.get_callable_name
3020

@@ -255,3 +245,19 @@ def test_str_size():
255245
]
256246
result = subprocess.check_output(call).decode()[-4:-1].strip("\n")
257247
assert int(result) == int(expected)
248+
249+
250+
def test_bz2_missing_import():
251+
# Check whether bz2 missing import is handled correctly (issue #53857)
252+
code = (
253+
"import pytest\n"
254+
"sys.modules.pop('bz2', None)\n"
255+
"import pandas\n"
256+
"assert 'bz2' not in sys.modules\n"
257+
"from pandas.compat import get_bz2_file\n"
258+
"msg = 'bz2 module not available.'\n"
259+
"with pytest.raises(RuntimeError, match=msg):\n"
260+
"\tget_bz2_file()"
261+
)
262+
call = [sys.executable, "-c", code]
263+
subprocess.check_output(call)

0 commit comments

Comments
 (0)