Skip to content

Commit 0d4dc56

Browse files
committed
use traceback
1 parent b8132ce commit 0d4dc56

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

tests/system/small/test_anywidget.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import traceback
16+
1517
import pandas as pd
1618
import pytest
1719

@@ -20,6 +22,31 @@
2022
pytest.importorskip("anywidget")
2123

2224

25+
@pytest.fixture(scope="module", autouse=True)
26+
def cleanup_session(session):
27+
"""Ensure comprehensive cleanup happens after all tests in this module."""
28+
yield
29+
try:
30+
# Force cleanup of anonymous dataset and all temporary tables
31+
if hasattr(session, "_anon_dataset_manager") and session._anon_dataset_manager:
32+
session._anon_dataset_manager.close()
33+
34+
# Also call the main session cleanup
35+
session.close()
36+
except Exception as e:
37+
traceback.print_exception(type(e), e, None)
38+
# Try the BigFrames cleanup function as fallback
39+
try:
40+
import bigframes.pandas as bpd
41+
42+
bpd.clean_up_by_session_id(
43+
session.session_id, location=session._location, project=session._project
44+
)
45+
except Exception as cleanup_error:
46+
print(f"Warning: Fallback cleanup also failed: {cleanup_error}")
47+
traceback.print_exception(type(cleanup_error), cleanup_error, None)
48+
49+
2350
@pytest.fixture(scope="module")
2451
def paginated_pandas_df() -> pd.DataFrame:
2552
"""Create a test DataFrame with exactly 3 pages of manually defined data."""
@@ -88,18 +115,6 @@ def table_widget(paginated_bf_df: bf.dataframe.DataFrame):
88115
return widget
89116

90117

91-
@pytest.fixture(scope="module", autouse=True)
92-
def cleanup_session(session):
93-
"""Ensure session cleanup happens after all tests in this module."""
94-
yield
95-
# Force cleanup of all temporary resources if session is still active
96-
try:
97-
session.close()
98-
except Exception:
99-
# Session may already be closed by the global fixture
100-
pass
101-
102-
103118
def _assert_html_matches_pandas_slice(
104119
table_html: str,
105120
expected_pd_slice: pd.DataFrame,

0 commit comments

Comments
 (0)